Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0525c6b

Browse filesBrowse 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 0525c6b
Copy full SHA for 0525c6b

File tree

Expand file treeCollapse file tree

3 files changed

+27
-10
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-10
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,12 @@ def __init__(self, fig, rect,
556556
self.update(kwargs)
557557

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

562562
if self.yaxis is not None:
563-
self._ycid = self.yaxis.callbacks.connect('units finalize',
564-
self.relim)
563+
self._ycid = self.yaxis.callbacks.connect(
564+
'units finalize', lambda: self._on_units_changed(scaley=True))
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, scalex=False, scaley=False):
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(scalex=scalex, scaley=scaley)
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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_units.py
-1Lines 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

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ def __init__(self, fig, rect=None, *args, **kwargs):
110110
# func used to format z -- fall back on major formatters
111111
self.fmt_zdata = None
112112

113-
if zscale is not None :
113+
if zscale is not None:
114114
self.set_zscale(zscale)
115115

116-
if self.zaxis is not None :
117-
self._zcid = self.zaxis.callbacks.connect('units finalize',
118-
self.relim)
119-
else :
116+
if self.zaxis is not None:
117+
self._zcid = self.zaxis.callbacks.connect(
118+
'units finalize', lambda: self._on_units_changed(scalez=True))
119+
else:
120120
self._zcid = None
121121

122122
self._ready = 1
@@ -307,6 +307,15 @@ def get_axis_position(self):
307307
zhigh = tc[0][2] > tc[2][2]
308308
return xhigh, yhigh, zhigh
309309

310+
def _on_units_changed(self, scalex=False, scaley=False, scalez=False):
311+
"""
312+
Callback for processing changes to axis units.
313+
314+
Currently forces updates of data limits and view limits.
315+
"""
316+
self.relim()
317+
self.autoscale_view(scalex=scalex, scaley=scaley, scalez=scalez)
318+
310319
def update_datalim(self, xys, **kwargs):
311320
pass
312321

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.