Skip to content

Commit

Permalink
It is now possible to control the initial plot size
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuederle committed Oct 31, 2024
1 parent 6f67e45 commit 1c538de
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 9 additions & 3 deletions imucal/calibration_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class CalibrationGui:
>>> labels["label2"] # First value is start, second value is end of region
(500, 758)
Notes
-----
If the toolbar is not visible at the bottom of the GUI, try reducing the `initial_figsize` parameter, when
creating the GUI.
"""

section_list = None
Expand Down Expand Up @@ -65,6 +70,7 @@ def __init__(
expected_labels: Sequence[str],
title: Optional[str] = None,
master: Optional[tk.Frame] = None,
initial_figsize=(20, 10),
) -> None:
"""Launch new GUI instance.
Expand Down Expand Up @@ -122,7 +128,7 @@ def __init__(self, canvas, window) -> None:
self._create_sidebar()

# Create a container
self.fig, self.axs = _create_figure(acc, gyro)
self.fig, self.axs = _create_figure(acc, gyro, figsize=initial_figsize)

self.canvas = FigureCanvasTkAgg(self.fig, master=self.main_area)
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
Expand Down Expand Up @@ -281,10 +287,10 @@ def _n_labels(self):
return sum(all(v) for v in self.section_list.values())


def _create_figure(acc, gyro):
def _create_figure(acc, gyro, figsize=(20, 10)):
from matplotlib.figure import Figure

fig = Figure(figsize=(20, 10))
fig = Figure(figsize=figsize)
ax1 = fig.add_subplot(211)
lines = ax1.plot(acc)
ax1.grid(True)
Expand Down
13 changes: 10 additions & 3 deletions imucal/ferraris_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ def ferraris_regions_from_interactive_plot(
acc_cols: Iterable[str] = ("acc_x", "acc_y", "acc_z"),
gyr_cols: Iterable[str] = ("gyr_x", "gyr_y", "gyr_z"),
title: Optional[str] = None,
figsize=(20, 10),
) -> tuple[FerrarisSignalRegions, pd.DataFrame]:
"""Create a Calibration object by selecting the individual signal sections manually in an interactive GUI.
Expand Down Expand Up @@ -497,6 +498,9 @@ def ferraris_regions_from_interactive_plot(
The name of the 3 acceleration columns in order x,y,z.
title :
Optional title of the plot window
figsize :
The initial size of the plot window.
If you can not see the toolbar at the bottom, it might help to reduce the figure size.
Returns
-------
Expand All @@ -515,14 +519,16 @@ def ferraris_regions_from_interactive_plot(
acc = data[list(acc_cols)].to_numpy()
gyr = data[list(gyr_cols)].to_numpy()

section_list = _find_ferraris_regions_interactive(acc, gyr, title=title)
section_list = _find_ferraris_regions_interactive(acc, gyr, title=title, figsize=figsize)
return (
ferraris_regions_from_section_list(data, section_list, gyr_cols=gyr_cols, acc_cols=acc_cols),
section_list,
)


def _find_ferraris_regions_interactive(acc: np.ndarray, gyro: np.ndarray, title: Optional[str] = None):
def _find_ferraris_regions_interactive(
acc: np.ndarray, gyro: np.ndarray, title: Optional[str] = None, figsize=(20, 10)
):
"""Prepare the calibration data for the later calculation of calibration matrices.
Parameters
Expand All @@ -534,10 +540,11 @@ def _find_ferraris_regions_interactive(acc: np.ndarray, gyro: np.ndarray, title:
title :
Optional title for the Calibration GUI
"""
from imucal.calibration_gui import CalibrationGui

plot = CalibrationGui(acc, gyro, FerrarisCalibration.FERRARIS_SECTIONS, title=title)
plot = CalibrationGui(acc, gyro, FerrarisCalibration.FERRARIS_SECTIONS, title=title, initial_figsize=figsize)

section_list = plot.section_list

Expand Down

0 comments on commit 1c538de

Please sign in to comment.