|
1 | 1 | from collections import OrderedDict |
2 | 2 | from contextlib import ExitStack |
| 3 | +import functools |
3 | 4 | import inspect |
4 | 5 | import itertools |
5 | 6 | import logging |
@@ -561,13 +562,10 @@ def __init__(self, fig, rect, |
561 | 562 |
|
562 | 563 | self.update(kwargs) |
563 | 564 |
|
564 | | - if self.xaxis is not None: |
565 | | - self._xcid = self.xaxis.callbacks.connect( |
566 | | - 'units finalize', lambda: self._on_units_changed(scalex=True)) |
567 | | - |
568 | | - if self.yaxis is not None: |
569 | | - self._ycid = self.yaxis.callbacks.connect( |
570 | | - 'units finalize', lambda: self._on_units_changed(scaley=True)) |
| 565 | + for name, axis in self._get_axis_map().items(): |
| 566 | + axis.callbacks._pickled_cids.add( |
| 567 | + axis.callbacks.connect( |
| 568 | + 'units finalize', self._unit_change_handler(name))) |
571 | 569 |
|
572 | 570 | rcParams = mpl.rcParams |
573 | 571 | self.tick_params( |
@@ -2130,14 +2128,17 @@ def add_container(self, container): |
2130 | 2128 | container._remove_method = self.containers.remove |
2131 | 2129 | return container |
2132 | 2130 |
|
2133 | | - def _on_units_changed(self, scalex=False, scaley=False): |
| 2131 | + def _unit_change_handler(self, axis_name, event=None): |
2134 | 2132 | """ |
2135 | | - Callback for processing changes to axis units. |
2136 | | -
|
2137 | | - Currently requests updates of data limits and view limits. |
| 2133 | + Process axis units changes: requests updates to data and view limits. |
2138 | 2134 | """ |
| 2135 | + if event is None: # Allow connecting `self._unit_change_handler(name)` |
| 2136 | + return functools.partial( |
| 2137 | + self._unit_change_handler, axis_name, event=object()) |
| 2138 | + _api.check_in_list(self._get_axis_map(), axis_name=axis_name) |
2139 | 2139 | self.relim() |
2140 | | - self._request_autoscale_view(scalex=scalex, scaley=scaley) |
| 2140 | + self._request_autoscale_view(scalex=(axis_name == "x"), |
| 2141 | + scaley=(axis_name == "y")) |
2141 | 2142 |
|
2142 | 2143 | def relim(self, visible_only=False): |
2143 | 2144 | """ |
|
0 commit comments