From 621ce36875f252a615bdd75bed7c0f5d7653b325 Mon Sep 17 00:00:00 2001 From: Nick Tremaroli Date: Mon, 8 Apr 2024 17:39:45 +0200 Subject: [PATCH] Rebased for recent changes --- .../plotter/matplotlib_viewer_canvas.py | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py b/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py index 2e90ecf..0793902 100644 --- a/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py +++ b/robot_log_visualizer/plotter/matplotlib_viewer_canvas.py @@ -185,24 +185,34 @@ def on_pick(self, event): blit=True, ) - def update_plots(self, paths, legends): + def update_plots(self, paths, legends, realtimePlot): self.axes.cla() + realtimeColorIndex = 0 for path, legend in zip(paths, legends): path_string = "/".join(path) legend_string = "/".join(legend[1:]) - if path_string not in self.active_paths.keys(): - data = self.signal_provider.data - for key in path[:-1]: - data = data[key] - try: - datapoints = data["data"][:, int(path[-1])] - except IndexError: - # This happens in the case the variable is a scalar. - datapoints = data["data"][:] + data = self.signal_provider.data.copy() + for key in path[:-1]: + data = data[key] + try: + datapoints = data["data"][:, int(path[-1])] + except IndexError: + # This happens in the case the variable is a scalar. + datapoints = data["data"][:] - timestamps = data["timestamps"] - self.signal_provider.initial_time + timestamps = data["timestamps"] - self.signal_provider.initial_time + if realtimePlot: + (self.active_paths[path_string],) = self.axes.plot( + timestamps, + datapoints, + label=legend_string, + picker=True, + color=self.color_palette.get_color(realtimeColorIndex), + ) + realtimeColorIndex = realtimeColorIndex + 1 + else: (self.active_paths[path_string],) = self.axes.plot( timestamps, datapoints, @@ -211,6 +221,7 @@ def update_plots(self, paths, legends): color=next(self.color_palette), ) + paths_to_be_canceled = [] for active_path in self.active_paths.keys(): path = active_path.split("/") @@ -232,8 +243,10 @@ def update_plots(self, paths, legends): # Since a new plot has been added/removed we delete the old animation and we create a new one # TODO: this part could be optimized + self.vertical_line_anim._stop() self.axes.legend() + self.axes.grid() if not self.frame_legend: self.frame_legend = self.axes.legend().get_frame()