Skip to content

Commit a118261

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 3b97e55 commit a118261

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/matplotlib/axes/_base.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ def __init__(self, fig, rect,
556556

557557
if self.xaxis is not None:
558558
self._xcid = self.xaxis.callbacks.connect('units finalize',
559-
self.relim)
559+
self._on_units_changed)
560560

561561
if self.yaxis is not None:
562562
self._ycid = self.yaxis.callbacks.connect('units finalize',
563-
self.relim)
563+
self._on_units_changed)
564564

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

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

lib/matplotlib/tests/test_units.py

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def convert(value, unit, axis):
7575
ax.axvline(Quantity(120, 'minutes'), color='tab:green')
7676
ax.yaxis.set_units('inches')
7777
ax.xaxis.set_units('seconds')
78-
ax.autoscale_view()
7978

8079
assert qc.convert.called
8180
assert qc.axisinfo.called

lib/mpl_toolkits/mplot3d/axes3d.py

+1-1
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)