Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8e0f8b4

Browse files
committedFeb 3, 2025·
use set_ybound
1 parent 49317a4 commit 8e0f8b4

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed
 

‎src/silx/gui/plot/backends/BackendMatplotlib.py

+6-22
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ def __init__(self, plot, parent=None):
552552
for axis in (self.ax.yaxis, self.ax.xaxis, self.ax2.yaxis, self.ax2.xaxis):
553553
axis.set_major_formatter(DefaultTickFormatter())
554554

555+
self.ax.set_autoscaley_on(True)
555556
self.ax2.set_autoscaley_on(True)
556557

557558
# this works but the figure color is left
@@ -1193,19 +1194,9 @@ def setLimits(self, xmin, xmax, ymin, ymax, y2min=None, y2max=None):
11931194
self.ax.set_xlim(min(xmin, xmax), max(xmin, xmax))
11941195

11951196
if y2min is not None and y2max is not None:
1196-
if self.ax2.get_autoscaley_on():
1197-
pass
1198-
elif not self.isYAxisInverted():
1199-
self.ax2.set_ylim(min(y2min, y2max), max(y2min, y2max))
1200-
else:
1201-
self.ax2.set_ylim(max(y2min, y2max), min(y2min, y2max))
1197+
self.ax2.set_ybound(y2min, y2max)
12021198

1203-
if self.ax.get_autoscaley_on():
1204-
pass
1205-
elif not self.isYAxisInverted():
1206-
self.ax.set_ylim(min(ymin, ymax), max(ymin, ymax))
1207-
else:
1208-
self.ax.set_ylim(max(ymin, ymax), min(ymin, ymax))
1199+
self.ax.set_ybound(ymin, ymax)
12091200

12101201
self._updateMarkers()
12111202

@@ -1237,8 +1228,6 @@ def getGraphYLimits(self, axis):
12371228

12381229
def setGraphYLimits(self, ymin, ymax, axis):
12391230
ax = self.ax2 if axis == "right" else self.ax
1240-
if ymax < ymin:
1241-
ymin, ymax = ymax, ymin
12421231
self._dirtyLimits = True
12431232

12441233
if self.isKeepDataAspectRatio():
@@ -1250,14 +1239,11 @@ def setGraphYLimits(self, ymin, ymax, axis):
12501239
xmin, xmax = ax.get_xbound()
12511240
curYMin, curYMax = ax.get_ybound()
12521241

1253-
newXRange = (xmax - xmin) * (ymax - ymin) / (curYMax - curYMin)
1242+
newXRange = (xmax - xmin) * abs(ymax - ymin) / (curYMax - curYMin)
12541243
xcenter = 0.5 * (xmin + xmax)
12551244
ax.set_xlim(xcenter - 0.5 * newXRange, xcenter + 0.5 * newXRange)
12561245

1257-
if not self.isYAxisInverted():
1258-
ax.set_ylim(ymin, ymax)
1259-
else:
1260-
ax.set_ylim(ymax, ymin)
1246+
ax.set_ybound(ymin, ymax)
12611247

12621248
self._updateMarkers()
12631249

@@ -1319,7 +1305,7 @@ def setYAxisLogarithmic(self, flag):
13191305
dataRange = self._plot.getDataRange()[dataRangeIndex]
13201306
if dataRange is None:
13211307
dataRange = 1, 100 # Fallback
1322-
axis.set_ylim(*dataRange)
1308+
axis.set_ybound(*dataRange)
13231309
redraw = True
13241310
if redraw:
13251311
self.draw()
@@ -1351,8 +1337,6 @@ def isKeepDataAspectRatio(self):
13511337
def setKeepDataAspectRatio(self, flag):
13521338
self.ax.set_aspect(1.0 if flag else "auto")
13531339
self.ax2.set_aspect(1.0 if flag else "auto")
1354-
self.ax.set_autoscaley_on(flag)
1355-
self.ax2.set_autoscaley_on(flag)
13561340

13571341
def setGraphGrid(self, which):
13581342
self.ax.grid(False, which="both") # Disable all grid first

0 commit comments

Comments
 (0)
Please sign in to comment.