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

Skip to content

Commit e48f14e

Browse files
committed
ENH: Update view limits on units change
This adds a independent callback for units changes that both updates the data limits (relim) as well as the view limits (autoscale_view).
1 parent 6eb96c8 commit e48f14e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,11 +557,11 @@ def __init__(self, fig, rect,
557557

558558
if self.xaxis is not None:
559559
self._xcid = self.xaxis.callbacks.connect('units finalize',
560-
self.relim)
560+
self._on_units_changed)
561561

562562
if self.yaxis is not None:
563563
self._ycid = self.yaxis.callbacks.connect('units finalize',
564-
self.relim)
564+
self._on_units_changed)
565565

566566
self.tick_params(
567567
top=rcParams['xtick.top'] and rcParams['xtick.minor.top'],
@@ -1891,6 +1891,15 @@ def add_container(self, container):
18911891
container.set_remove_method(lambda h: self.containers.remove(h))
18921892
return container
18931893

1894+
def _on_units_changed(self):
1895+
"""
1896+
Callback for processing changes to axis units.
1897+
1898+
Currently forces updates of data limits and view limits.
1899+
"""
1900+
self.relim()
1901+
self.autoscale_view()
1902+
18941903
def relim(self, visible_only=False):
18951904
"""
18961905
Recompute the data limits based on current artists. If you want to

lib/matplotlib/tests/test_units.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def convert(value, unit, axis):
7676
ax.axvline(Quantity(120, 'minutes'), color='tab:green')
7777
ax.yaxis.set_units('inches')
7878
ax.xaxis.set_units('seconds')
79-
ax.autoscale_view()
8079

8180
assert qc.convert.called
8281
assert qc.axisinfo.called

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(self, fig, rect=None, *args, **kwargs):
115115

116116
if self.zaxis is not None :
117117
self._zcid = self.zaxis.callbacks.connect('units finalize',
118-
self.relim)
118+
self._on_units_changed)
119119
else :
120120
self._zcid = None
121121

0 commit comments

Comments
 (0)