From 334390abdb70e77eabc1b75580f096a1c81f3689 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 22 Apr 2025 11:22:06 +0200 Subject: [PATCH] Sample data: Clear plots at redraw. --- View/sample_data_tab.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/View/sample_data_tab.py b/View/sample_data_tab.py index 7177e3b..0a22137 100644 --- a/View/sample_data_tab.py +++ b/View/sample_data_tab.py @@ -64,6 +64,7 @@ class SampleDataTab(QWidget): super().__init__() icon_folder = QIcon(os.path.join("icons", "folder.png")) + self._setup_attrs() ### --- General layout of widgets --- @@ -257,6 +258,11 @@ class SampleDataTab(QWidget): self.combobox_PSD_plot.currentTextChanged.connect(self.plot_PSD_fine_and_sand_sediments) + def _setup_attrs(self): + self.figure_plot_sample_position_on_transect = None + self.figure_total_concentration = None + self.figure_plot_PSD = None + # -------------------- Functions for Sample Data Tab -------------------- def retranslate_data_sample_tab(self): @@ -789,6 +795,9 @@ class SampleDataTab(QWidget): self.verticalLayout_groupbox_plot_transect\ .removeWidget(self.canvas_plot_sample_position_on_transect) + if self.figure_plot_sample_position_on_transect is not None: + self.figure_plot_sample_position_on_transect.clear() + fig, axis = plt.subplots(nrows=1, ncols=1, layout="constrained") self.figure_plot_sample_position_on_transect = fig @@ -1414,6 +1423,9 @@ class SampleDataTab(QWidget): self.verticalLayout_groupbox_plot_total_concentration.removeWidget(self.canvas_plot_total_concentration) self.verticalLayout_groupbox_plot_total_concentration.removeWidget(self.toolbar_plot_total_concentration) + if self.figure_total_concentration is not None: + self.figure_total_concentration.clear() + self.figure_total_concentration, self.axis_total_concentration \ = plt.subplots(nrows=1, ncols=1, layout="constrained") self.canvas_plot_total_concentration = FigureCanvas(self.figure_total_concentration) @@ -1699,6 +1711,9 @@ class SampleDataTab(QWidget): self.verticalLayout_groupbox_plot_PSD.removeWidget(self.canvas_plot_PSD) self.verticalLayout_groupbox_plot_PSD.removeWidget(self.toolbar_plot_PSD) + if self.figure_plot_PSD is not None: + self.figure_plot_PSD.clear() + self.figure_plot_PSD, self.axis_plot_PSD \ = plt.subplots(nrows=1, ncols=2, layout="constrained") self.canvas_plot_PSD = FigureCanvas(self.figure_plot_PSD)