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 0b836ed

Browse filesBrowse files
committed
Move towards having get_shared_{x,y}_axes return immutable views.
Directly calling join() on the Groupers is not sufficient to share axes, anyways, so don't let users do that.
1 parent 27cfec2 commit 0b836ed
Copy full SHA for 0b836ed

File tree

Expand file treeCollapse file tree

5 files changed

+42
-8
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+42
-8
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Modifications to the Groupers returned by ``get_shared_x_axes`` and ``get_shared_y_axes``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... are deprecated. In the future, these methods will return immutable views
4+
on the grouper structures. Note that previously, calling e.g. ``join()``
5+
would already fail to set up the correct structures for sharing axes; use
6+
`.Axes.sharex` or `.Axes.sharey` instead.

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4603,9 +4603,9 @@ def twiny(self):
46034603
return ax2
46044604

46054605
def get_shared_x_axes(self):
4606-
"""Return a reference to the shared axes Grouper object for x axes."""
4607-
return self._shared_axes["x"]
4606+
"""Return an immutable view on the shared x-axes Grouper."""
4607+
return cbook.GrouperView(self._shared_axes["x"])
46084608

46094609
def get_shared_y_axes(self):
4610-
"""Return a reference to the shared axes Grouper object for y axes."""
4611-
return self._shared_axes["y"]
4610+
"""Return an immutable view on the shared y-axes Grouper."""
4611+
return cbook.GrouperView(self._shared_axes["y"])

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,9 +3180,9 @@ def release_zoom(self, event):
31803180
for i, ax in enumerate(self._zoom_info.axes):
31813181
# Detect whether this Axes is twinned with an earlier Axes in the
31823182
# list of zoomed Axes, to avoid double zooming.
3183-
twinx = any(ax.get_shared_x_axes().joined(ax, prev)
3183+
twinx = any(ax._shared_axes["x"].joined(ax, prev)
31843184
for prev in self._zoom_info.axes[:i])
3185-
twiny = any(ax.get_shared_y_axes().joined(ax, prev)
3185+
twiny = any(ax._shared_axes["y"].joined(ax, prev)
31863186
for prev in self._zoom_info.axes[:i])
31873187
ax._set_view_from_bbox(
31883188
(start_x, start_y, event.x, event.y),

‎lib/matplotlib/backend_tools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_tools.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ def _release(self, event):
835835
twinx, twiny = False, False
836836
if last_a:
837837
for la in last_a:
838-
if a.get_shared_x_axes().joined(a, la):
838+
if a._shared_axes["x"].joined(a, la):
839839
twinx = True
840-
if a.get_shared_y_axes().joined(a, la):
840+
if a._shared_axes["y"].joined(a, la):
841841
twiny = True
842842
last_a.append(a)
843843

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,34 @@ def get_siblings(self, a):
902902
return [x() for x in siblings]
903903

904904

905+
class GrouperView:
906+
"""Immutable view over a `.Grouper`."""
907+
908+
def __init__(self, grouper):
909+
self._grouper = grouper
910+
911+
class _GrouperMethodForwarder:
912+
def __init__(self, deprecated_kw=None):
913+
self._deprecated_kw = deprecated_kw
914+
915+
def __set_name__(self, owner, name):
916+
wrapped = getattr(Grouper, name)
917+
forwarder = functools.wraps(wrapped)(
918+
lambda self, *args, **kwargs: wrapped(
919+
self._grouper, *args, **kwargs))
920+
if self._deprecated_kw:
921+
forwarder = _api.deprecated(**self._deprecated_kw)(forwarder)
922+
setattr(owner, name, forwarder)
923+
924+
__contains__ = _GrouperMethodForwarder()
925+
__iter__ = _GrouperMethodForwarder()
926+
joined = _GrouperMethodForwarder()
927+
get_siblings = _GrouperMethodForwarder()
928+
clean = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
929+
join = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
930+
remove = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
931+
932+
905933
def simple_linear_interpolation(a, steps):
906934
"""
907935
Resample an array with ``steps - 1`` points between original point pairs.

0 commit comments

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