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

Skip to content

Commit 63454db

Browse files
committed
Force autoscaling immediately after setting a scale.
1 parent cf2ef39 commit 63454db

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3252,20 +3252,26 @@ def set_xscale(self, value, **kwargs):
32523252
- `matplotlib.scale.SymmetricalLogScale`
32533253
- `matplotlib.scale.LogitScale`
32543254
3255-
32563255
Notes
32573256
-----
32583257
By default, Matplotlib supports the above mentioned scales.
32593258
Additionally, custom scales may be registered using
32603259
`matplotlib.scale.register_scale`. These scales can then also
32613260
be used here.
32623261
"""
3262+
old_default_lims = (self.xaxis.get_major_locator()
3263+
.nonsingular(-np.inf, np.inf))
32633264
g = self.get_shared_x_axes()
32643265
for ax in g.get_siblings(self):
32653266
ax.xaxis._set_scale(value, **kwargs)
32663267
ax._update_transScale()
32673268
ax.stale = True
3268-
self._request_autoscale_view(scaley=False)
3269+
new_default_lims = (self.xaxis.get_major_locator()
3270+
.nonsingular(-np.inf, np.inf))
3271+
if old_default_lims != new_default_lims:
3272+
# Force autoscaling now, to take advantage of the scale locator's
3273+
# nonsingular() before it possibly gets swapped out by the user.
3274+
self.autoscale_view(scaley=False)
32693275

32703276
@cbook._make_keyword_only("3.2", "minor")
32713277
def get_xticks(self, minor=False):
@@ -3637,20 +3643,26 @@ def set_yscale(self, value, **kwargs):
36373643
- `matplotlib.scale.SymmetricalLogScale`
36383644
- `matplotlib.scale.LogitScale`
36393645
3640-
36413646
Notes
36423647
-----
36433648
By default, Matplotlib supports the above mentioned scales.
36443649
Additionally, custom scales may be registered using
36453650
`matplotlib.scale.register_scale`. These scales can then also
36463651
be used here.
36473652
"""
3653+
old_default_lims = (self.yaxis.get_major_locator()
3654+
.nonsingular(-np.inf, np.inf))
36483655
g = self.get_shared_y_axes()
36493656
for ax in g.get_siblings(self):
36503657
ax.yaxis._set_scale(value, **kwargs)
36513658
ax._update_transScale()
36523659
ax.stale = True
3653-
self._request_autoscale_view(scalex=False)
3660+
new_default_lims = (self.yaxis.get_major_locator()
3661+
.nonsingular(-np.inf, np.inf))
3662+
if old_default_lims != new_default_lims:
3663+
# Force autoscaling now, to take advantage of the scale locator's
3664+
# nonsingular() before it possibly gets swapped out by the user.
3665+
self.autoscale_view(scalex=False)
36543666

36553667
@cbook._make_keyword_only("3.2", "minor")
36563668
def get_yticks(self, minor=False):

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,7 @@ def test_log_scales():
21732173
def test_log_scales_no_data():
21742174
_, ax = plt.subplots()
21752175
ax.set(xscale="log", yscale="log")
2176+
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
21762177
assert ax.get_xlim() == ax.get_ylim() == (1, 10)
21772178

21782179

0 commit comments

Comments
 (0)