Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3a1319

Browse files
committed
Better logic for defaults
1 parent 3164ce1 commit c3a1319

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2857,8 +2857,8 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
28572857
if self.get_yscale() == 'log':
28582858
y_stickies = y_stickies[y_stickies > 0]
28592859

2860-
def handle_single_axis(scale, autoscaleon, shared_axes, interval,
2861-
minpos, axis, margin, stickies, set_bound):
2860+
def handle_single_axis(scale, autoscaleon, shared_axes, name,
2861+
axis, margin, stickies, set_bound):
28622862

28632863
if not (scale and autoscaleon):
28642864
return # nothing to do...
@@ -2870,12 +2870,16 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
28702870
x_values = []
28712871
minimum_minpos = np.inf
28722872
for ax in shared:
2873-
x_values.extend(getattr(ax.dataLim, interval))
2873+
x_values.extend(getattr(ax.dataLim, f"interval{name}"))
28742874
minimum_minpos = min(minimum_minpos,
2875-
getattr(ax.dataLim, minpos))
2875+
getattr(ax.dataLim, f"minpos{name}"))
28762876
x_values = np.extract(np.isfinite(x_values), x_values)
28772877
if x_values.size >= 1:
28782878
x0, x1 = (x_values.min(), x_values.max())
2879+
elif getattr(self._viewLim, f"mutated{name}")():
2880+
# No data, but explicit viewLims already set:
2881+
# in mutatedx or mutatedy.
2882+
return
28792883
else:
28802884
x0, x1 = (-np.inf, np.inf)
28812885
# If x0 and x1 are non finite, use the locator to figure out
@@ -2919,11 +2923,11 @@ def handle_single_axis(scale, autoscaleon, shared_axes, interval,
29192923
# End of definition of internal function 'handle_single_axis'.
29202924

29212925
handle_single_axis(
2922-
scalex, self._autoscaleXon, self._shared_x_axes, 'intervalx',
2923-
'minposx', self.xaxis, self._xmargin, x_stickies, self.set_xbound)
2926+
scalex, self._autoscaleXon, self._shared_x_axes, 'x',
2927+
self.xaxis, self._xmargin, x_stickies, self.set_xbound)
29242928
handle_single_axis(
2925-
scaley, self._autoscaleYon, self._shared_y_axes, 'intervaly',
2926-
'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound)
2929+
scaley, self._autoscaleYon, self._shared_y_axes, 'y',
2930+
self.yaxis, self._ymargin, y_stickies, self.set_ybound)
29272931

29282932
def _get_axis_list(self):
29292933
return self.xaxis, self.yaxis

lib/matplotlib/axis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ def update_units(self, data):
14571457
if default is not None and self.units is None:
14581458
self.set_units(default)
14591459

1460-
if neednew:
1460+
elif neednew:
14611461
self._update_axisinfo()
14621462
self.stale = True
14631463
return True
@@ -2268,7 +2268,8 @@ def set_default_intervals(self):
22682268
# docstring inherited
22692269
xmin, xmax = 0., 1.
22702270
# only change view if dataLim has not changed:
2271-
if not self.axes.dataLim.mutatedx():
2271+
if (not self.axes.dataLim.mutatedx() and
2272+
not self.axes.viewLim.mutatedx()):
22722273
if self.converter is not None:
22732274
info = self.converter.axisinfo(self.units, self)
22742275
if info.default_limits is not None:
@@ -2527,9 +2528,9 @@ def set_inverted(self, inverted):
25272528

25282529
def set_default_intervals(self):
25292530
# docstring inherited
2530-
print('Settimg y default ')
25312531
ymin, ymax = 0., 1.
2532-
if not self.axes.dataLim.mutatedy():
2532+
if (not self.axes.dataLim.mutatedy() and
2533+
not self.axes.viewLim.mutatedy()):
25332534
if self.converter is not None:
25342535
info = self.converter.axisinfo(self.units, self)
25352536
if info.default_limits is not None:

0 commit comments

Comments
 (0)