From 95e0f7b3cfc62cca9d20e4a5af5ce9aa0e79a677 Mon Sep 17 00:00:00 2001 From: payno Date: Tue, 21 Jan 2025 07:17:08 +0100 Subject: [PATCH 1/3] matplotlib backend: attempt to remove matplotlib warning on conflict between y limits and autoscale --- src/silx/gui/plot/backends/BackendMatplotlib.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/silx/gui/plot/backends/BackendMatplotlib.py b/src/silx/gui/plot/backends/BackendMatplotlib.py index 7ca5533544..b0da66aac7 100755 --- a/src/silx/gui/plot/backends/BackendMatplotlib.py +++ b/src/silx/gui/plot/backends/BackendMatplotlib.py @@ -1193,12 +1193,16 @@ def setLimits(self, xmin, xmax, ymin, ymax, y2min=None, y2max=None): self.ax.set_xlim(min(xmin, xmax), max(xmin, xmax)) if y2min is not None and y2max is not None: - if not self.isYAxisInverted(): + if self.ax2.get_autoscaley_on(): + pass + elif not self.isYAxisInverted(): self.ax2.set_ylim(min(y2min, y2max), max(y2min, y2max)) else: self.ax2.set_ylim(max(y2min, y2max), min(y2min, y2max)) - if not self.isYAxisInverted(): + if self.ax.get_autoscaley_on(): + pass + elif not self.isYAxisInverted(): self.ax.set_ylim(min(ymin, ymax), max(ymin, ymax)) else: self.ax.set_ylim(max(ymin, ymax), min(ymin, ymax)) @@ -1347,6 +1351,8 @@ def isKeepDataAspectRatio(self): def setKeepDataAspectRatio(self, flag): self.ax.set_aspect(1.0 if flag else "auto") self.ax2.set_aspect(1.0 if flag else "auto") + # self.ax.set_autoscaley_on(flag) + # self.ax2.set_autoscaley_on(flag) def setGraphGrid(self, which): self.ax.grid(False, which="both") # Disable all grid first From 49317a46b5748b21a1adaad896d2bdeb12d12f1b Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 3 Feb 2025 13:23:29 +0100 Subject: [PATCH 2/3] Uncomment set_autoscaley_on --- src/silx/gui/plot/backends/BackendMatplotlib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/silx/gui/plot/backends/BackendMatplotlib.py b/src/silx/gui/plot/backends/BackendMatplotlib.py index b0da66aac7..77b1942099 100755 --- a/src/silx/gui/plot/backends/BackendMatplotlib.py +++ b/src/silx/gui/plot/backends/BackendMatplotlib.py @@ -1351,8 +1351,8 @@ def isKeepDataAspectRatio(self): def setKeepDataAspectRatio(self, flag): self.ax.set_aspect(1.0 if flag else "auto") self.ax2.set_aspect(1.0 if flag else "auto") - # self.ax.set_autoscaley_on(flag) - # self.ax2.set_autoscaley_on(flag) + self.ax.set_autoscaley_on(flag) + self.ax2.set_autoscaley_on(flag) def setGraphGrid(self, which): self.ax.grid(False, which="both") # Disable all grid first From be9f3f8f172b31831d0307e2b35520b09e6fa821 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 3 Feb 2025 15:13:40 +0100 Subject: [PATCH 3/3] Use set_ylim auto argument --- .../gui/plot/backends/BackendMatplotlib.py | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/silx/gui/plot/backends/BackendMatplotlib.py b/src/silx/gui/plot/backends/BackendMatplotlib.py index 77b1942099..56fc57b816 100755 --- a/src/silx/gui/plot/backends/BackendMatplotlib.py +++ b/src/silx/gui/plot/backends/BackendMatplotlib.py @@ -1192,20 +1192,17 @@ def setLimits(self, xmin, xmax, ymin, ymax, y2min=None, y2max=None): self._dirtyLimits = True self.ax.set_xlim(min(xmin, xmax), max(xmin, xmax)) + keepRatio = self.isKeepDataAspectRatio() if y2min is not None and y2max is not None: - if self.ax2.get_autoscaley_on(): - pass - elif not self.isYAxisInverted(): - self.ax2.set_ylim(min(y2min, y2max), max(y2min, y2max)) + if not self.isYAxisInverted(): + self.ax2.set_ylim(min(y2min, y2max), max(y2min, y2max), auto=keepRatio) else: - self.ax2.set_ylim(max(y2min, y2max), min(y2min, y2max)) + self.ax2.set_ylim(max(y2min, y2max), min(y2min, y2max), auto=keepRatio) - if self.ax.get_autoscaley_on(): - pass - elif not self.isYAxisInverted(): - self.ax.set_ylim(min(ymin, ymax), max(ymin, ymax)) + if not self.isYAxisInverted(): + self.ax.set_ylim(min(ymin, ymax), max(ymin, ymax), auto=keepRatio) else: - self.ax.set_ylim(max(ymin, ymax), min(ymin, ymax)) + self.ax.set_ylim(max(ymin, ymax), min(ymin, ymax), auto=keepRatio) self._updateMarkers() @@ -1254,10 +1251,11 @@ def setGraphYLimits(self, ymin, ymax, axis): xcenter = 0.5 * (xmin + xmax) ax.set_xlim(xcenter - 0.5 * newXRange, xcenter + 0.5 * newXRange) + keepRatio = self.isKeepDataAspectRatio() if not self.isYAxisInverted(): - ax.set_ylim(ymin, ymax) + ax.set_ylim(ymin, ymax, auto=keepRatio) else: - ax.set_ylim(ymax, ymin) + ax.set_ylim(ymax, ymin, auto=keepRatio) self._updateMarkers() @@ -1319,7 +1317,7 @@ def setYAxisLogarithmic(self, flag): dataRange = self._plot.getDataRange()[dataRangeIndex] if dataRange is None: dataRange = 1, 100 # Fallback - axis.set_ylim(*dataRange) + axis.set_ylim(*dataRange, auto=self.isKeepDataAspectRatio()) redraw = True if redraw: self.draw() @@ -1351,8 +1349,6 @@ def isKeepDataAspectRatio(self): def setKeepDataAspectRatio(self, flag): self.ax.set_aspect(1.0 if flag else "auto") self.ax2.set_aspect(1.0 if flag else "auto") - self.ax.set_autoscaley_on(flag) - self.ax2.set_autoscaley_on(flag) def setGraphGrid(self, which): self.ax.grid(False, which="both") # Disable all grid first