From f96cee145cbf2abc2fc0723929ea6c317461bb4e Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Mon, 18 Dec 2023 15:37:22 +0100 Subject: [PATCH] HS: Fix Plot relim at update. --- src/View/HydraulicStructures/PlotAC.py | 7 +++---- src/View/HydraulicStructures/PlotKPC.py | 12 ++++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/View/HydraulicStructures/PlotAC.py b/src/View/HydraulicStructures/PlotAC.py index c3b68cef..4d171968 100644 --- a/src/View/HydraulicStructures/PlotAC.py +++ b/src/View/HydraulicStructures/PlotAC.py @@ -77,14 +77,10 @@ class PlotAC(PamhyrPlot): if self._current_profile is None: self.line_kp = None else: - profile = self._current_profile x = profile.get_station() z = profile.z() - self.canvas.axes.set_xlim( - left=min(x), right=max(x) - ) self.line_kp, = self.canvas.axes.plot( x, z, linestyle="solid", @@ -92,6 +88,9 @@ class PlotAC(PamhyrPlot): color='grey', ) + self.canvas.axes.relim() + self.canvas.axes.autoscale_view() + self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle() if self.toolbar is not None: diff --git a/src/View/HydraulicStructures/PlotKPC.py b/src/View/HydraulicStructures/PlotKPC.py index 47ef289c..f72cf7fc 100644 --- a/src/View/HydraulicStructures/PlotKPC.py +++ b/src/View/HydraulicStructures/PlotKPC.py @@ -83,17 +83,12 @@ class PlotKPC(PamhyrPlot): z_min = reach.reach.get_z_min() z_max = reach.reach.get_z_max() - self.canvas.axes.set_xlim( - left=min(kp), right=max(kp) - ) - self.line_kp_zmin, = self.canvas.axes.plot( kp, z_min, color='grey', lw=1. ) if len(kp) != 0: - self.line_kp_zmin_zmax = self.canvas.axes.vlines( x=kp, ymin=z_min, ymax=z_max, @@ -110,6 +105,7 @@ class PlotKPC(PamhyrPlot): color='red', lw=1. ) + self.canvas.axes.relim() self.canvas.figure.tight_layout() self.canvas.figure.canvas.draw_idle() if self.toolbar is not None: @@ -132,6 +128,7 @@ class PlotKPC(PamhyrPlot): kp = reach.reach.get_kp() z_min = reach.reach.get_z_min() z_max = reach.reach.get_z_max() + if self.profile is None: self.draw() else: @@ -142,20 +139,23 @@ class PlotKPC(PamhyrPlot): self.canvas.axes.relim() self.canvas.axes.autoscale_view() - self.canvas.figure.canvas.draw_idle() def clear(self): if self.profile is not None: self.profile.set_data([], []) + if self.line_kp_zmin_zmax is not None: self.line_kp_zmin_zmax.remove() self.line_kp_zmin_zmax = None + if self.line_kp_zmin is not None: self.line_kp_zmin.set_data([], []) + self.canvas.figure.canvas.draw_idle() def clear_profile(self): if self.profile is not None: self.profile.set_data([], []) + self.canvas.figure.canvas.draw_idle() -- GitLab