From 6c14e5ebf15318e135c8f51fcc3a9c038c0bf57e Mon Sep 17 00:00:00 2001
From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr>
Date: Mon, 22 May 2023 10:30:21 +0200
Subject: [PATCH] geometry: Plot update minor fix and autoscale.

---
 src/View/Geometry/PlotAC.py |  1 +
 src/View/Geometry/PlotXY.py | 55 ++++++++++++++++++++++++++-----------
 2 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/View/Geometry/PlotAC.py b/src/View/Geometry/PlotAC.py
index 56f96e39..da5f1149 100644
--- a/src/View/Geometry/PlotAC.py
+++ b/src/View/Geometry/PlotAC.py
@@ -327,5 +327,6 @@ class PlotAC(APlot):
             self.update_annotate_full(0)
 
         self.canvas.axes.relim()
+        self.canvas.axes.autoscale()
         self.canvas.axes.autoscale_view()
         self.canvas.figure.canvas.draw_idle()
diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py
index 86b93f8d..4293d8fc 100644
--- a/src/View/Geometry/PlotXY.py
+++ b/src/View/Geometry/PlotXY.py
@@ -104,6 +104,8 @@ class PlotXY(APlot):
             )
             self.after_plot_selected.set_visible(False)
 
+        self.canvas.axes.autoscale_view(True, True, True)
+        self.canvas.axes.autoscale()
         self.canvas.figure.tight_layout()
         self.canvas.figure.canvas.draw_idle()
         self.toolbar.update()
@@ -119,6 +121,40 @@ class PlotXY(APlot):
         if self.data is None:
             return
 
+        self.data.compute_guidelines()
+        x_complete = self.data.get_guidelines_x()
+        y_complete = self.data.get_guidelines_y()
+
+        for i in range(self.data.number_profiles):
+            if i < len(self.line_xy):
+                self.line_xy[i][0].set_data(
+                    self.data.profile(i).x(),
+                    self.data.profile(i).y()
+                )
+            else:
+                self.line_xy.append(
+                    self.canvas.axes.plot(
+                        self.data.profile(i).x(),
+                        self.data.profile(i).y(),
+                        lw=1., color='r',
+                        markersize=3, marker='+'
+                    )
+                )
+
+        for i in range(len(x_complete)):
+            if i < len(self.line_gl):
+                self.line_gl[i][0].set_data(
+                    x_complete[i],
+                    y_complete[i]
+                )
+            else:
+                self.line_gl.append(
+                    self.canvas.axes.plot(
+                        x_complete[i],
+                        y_complete[i]
+                    )
+                )
+
         if ind is not None and self.display_current:
             before = ind - 1
             after = ind + 1
@@ -141,22 +177,9 @@ class PlotXY(APlot):
                 self.after_plot_selected.set_data(self.data.profile(after).x(),
                                                   self.data.profile(after).y())
                 self.after_plot_selected.set_visible(True)
-        else:
-            for ind in range(self.data.number_profiles):
-                self.line_xy[ind][0].set_data(
-                    self.data.profile(ind).x(),
-                    self.data.profile(ind).y()
-                )
-
-            self.data.compute_guidelines()
-            x_complete = self.data.get_guidelines_x()
-            y_complete = self.data.get_guidelines_y()
-
-            for ind in range(len(self.line_gl)):
-                self.line_gl[ind][0].set_data(
-                    x_complete[ind],
-                    y_complete[ind]
-                )
 
+        self.canvas.axes.relim()
+        self.canvas.axes.autoscale()
+        self.canvas.axes.autoscale_view()
         self.canvas.figure.tight_layout()
         self.canvas.figure.canvas.draw_idle()
-- 
GitLab