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 4dcd5a0

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 95463c3 commit 4dcd5a0
Copy full SHA for 4dcd5a0

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
@@ -4727,9 +4727,9 @@ def twiny(self):
47274727
return ax2
47284728

47294729
def get_shared_x_axes(self):
4730-
"""Return a reference to the shared axes Grouper object for x axes."""
4731-
return self._shared_axes["x"]
4730+
"""Return an immutable view on the shared x-axes Grouper."""
4731+
return cbook.GrouperView(self._shared_axes["x"])
47324732

47334733
def get_shared_y_axes(self):
4734-
"""Return a reference to the shared axes Grouper object for y axes."""
4735-
return self._shared_axes["y"]
4734+
"""Return an immutable view on the shared y-axes Grouper."""
4735+
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
@@ -3216,9 +3216,9 @@ def release_zoom(self, event):
32163216
for i, ax in enumerate(self._zoom_info.axes):
32173217
# Detect whether this axes is twinned with an earlier axes in the
32183218
# list of zoomed axes, to avoid double zooming.
3219-
twinx = any(ax.get_shared_x_axes().joined(ax, prev)
3219+
twinx = any(ax._shared_axes["x"].joined(ax, prev)
32203220
for prev in self._zoom_info.axes[:i])
3221-
twiny = any(ax.get_shared_y_axes().joined(ax, prev)
3221+
twiny = any(ax._shared_axes["y"].joined(ax, prev)
32223222
for prev in self._zoom_info.axes[:i])
32233223
ax._set_view_from_bbox(
32243224
(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
@@ -876,6 +876,34 @@ def get_siblings(self, a):
876876
return [x() for x in siblings]
877877

878878

879+
class GrouperView:
880+
"""Immutable view over a `.Grouper`."""
881+
882+
def __init__(self, grouper):
883+
self._grouper = grouper
884+
885+
class _GrouperMethodForwarder:
886+
def __init__(self, deprecated_kw=None):
887+
self._deprecated_kw = deprecated_kw
888+
889+
def __set_name__(self, owner, name):
890+
wrapped = getattr(Grouper, name)
891+
forwarder = functools.wraps(wrapped)(
892+
lambda self, *args, **kwargs: wrapped(
893+
self._grouper, *args, **kwargs))
894+
if self._deprecated_kw:
895+
forwarder = _api.deprecated(**self._deprecated_kw)(forwarder)
896+
setattr(owner, name, forwarder)
897+
898+
__contains__ = _GrouperMethodForwarder()
899+
__iter__ = _GrouperMethodForwarder()
900+
joined = _GrouperMethodForwarder()
901+
get_siblings = _GrouperMethodForwarder()
902+
clean = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
903+
join = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
904+
remove = _GrouperMethodForwarder(deprecated_kw=dict(since="3.6"))
905+
906+
879907
def simple_linear_interpolation(a, steps):
880908
"""
881909
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.