Skip to content

Commit

Permalink
Enhance data handling in SignalProvider and improve plotting behavior…
Browse files Browse the repository at this point in the history
… in MatplotlibViewerCanvas in case of signal with only one datapoint (#91)
  • Loading branch information
GiulioRomualdi authored Dec 18, 2024
1 parent 76e2c97 commit 3f26b66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions robot_log_visualizer/file_reader/signal_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def __populate_numerical_data(self, file_object):
continue
if "data" in value.keys():
data[key] = {}
data[key]["data"] = np.squeeze(np.array(value["data"]))
data[key]["timestamps"] = np.squeeze(np.array(value["timestamps"]))
data[key]["data"] = np.atleast_1d(np.squeeze(np.array(value["data"])))
data[key]["timestamps"] = np.atleast_1d(np.squeeze(np.array(value["timestamps"])))

# if the initial or end time has been updated we can also update the entire timestamps dataset
if data[key]["timestamps"][0] < self.initial_time:
Expand Down
24 changes: 17 additions & 7 deletions robot_log_visualizer/plotter/matplotlib_viewer_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,23 @@ def update_plots(self, paths, legends):

timestamps = data["timestamps"] - self.signal_provider.initial_time

(self.active_paths[path_string],) = self.axes.plot(
timestamps,
datapoints,
label=legend_string,
picker=True,
color=next(self.color_palette),
)
if timestamps.size > 1:
(self.active_paths[path_string],) = self.axes.plot(
timestamps,
datapoints,
label=legend_string,
picker=True,
color=next(self.color_palette),
)
else:
(self.active_paths[path_string],) = self.axes.plot(
timestamps,
datapoints,
label=legend_string,
picker=True,
color=next(self.color_palette),
marker="o",
)

paths_to_be_canceled = []
for active_path in self.active_paths.keys():
Expand Down

0 comments on commit 3f26b66

Please sign in to comment.