From 3f26b667a14b54758959d4aa34c7cc5270fa54dc Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Wed, 18 Dec 2024 22:29:38 +0100 Subject: [PATCH] Enhance data handling in SignalProvider and improve plotting behavior in MatplotlibViewerCanvas in case of signal with only one datapoint (#91) --- .../file_reader/signal_provider.py | 4 ++-- .../plotter/matplotlib_viewer_canvas.py | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/robot_log_visualizer/file_reader/signal_provider.py b/robot_log_visualizer/file_reader/signal_provider.py index 6d92ea2..0d2bea8 100644 --- a/robot_log_visualizer/file_reader/signal_provider.py +++ b/robot_log_visualizer/file_reader/signal_provider.py @@ -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: diff --git a/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py b/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py index 84fd49f..643d8e7 100644 --- a/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py +++ b/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py @@ -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():