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 ca29425

Browse filesBrowse files
authored
Merge pull request #25904 from anntzer/ss
Support spine.set() in SpinesProxy.
2 parents 7506d1a + 877d977 commit ca29425
Copy full SHA for ca29425

File tree

3 files changed

+13
-4
lines changed
Filter options

3 files changed

+13
-4
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``SpinesProxy`` now supports calling the ``set()`` method
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
One can now call e.g. ``ax.spines[:].set(visible=False)``.

‎lib/matplotlib/spines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/spines.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def set_color(self, c):
479479

480480
class SpinesProxy:
481481
"""
482-
A proxy to broadcast ``set_*`` method calls to all contained `.Spines`.
482+
A proxy to broadcast ``set_*()`` and ``set()`` method calls to contained `.Spines`.
483483
484484
The proxy cannot be used for any other operations on its members.
485485
@@ -493,7 +493,7 @@ def __init__(self, spine_dict):
493493
def __getattr__(self, name):
494494
broadcast_targets = [spine for spine in self._spine_dict.values()
495495
if hasattr(spine, name)]
496-
if not name.startswith('set_') or not broadcast_targets:
496+
if (name != 'set' and not name.startswith('set_')) or not broadcast_targets:
497497
raise AttributeError(
498498
f"'SpinesProxy' object has no attribute '{name}'")
499499

@@ -531,8 +531,8 @@ class Spines(MutableMapping):
531531
532532
spines[:].set_visible(False)
533533
534-
The latter two indexing methods will return a `SpinesProxy` that broadcasts
535-
all ``set_*`` calls to its members, but cannot be used for any other
534+
The latter two indexing methods will return a `SpinesProxy` that broadcasts all
535+
``set_*()`` and ``set()`` calls to its members, but cannot be used for any other
536536
operation.
537537
"""
538538
def __init__(self, **kwargs):

‎lib/matplotlib/tests/test_spines.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_spines.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class SpineMock:
1212
def __init__(self):
1313
self.val = None
1414

15+
def set(self, **kwargs):
16+
vars(self).update(kwargs)
17+
1518
def set_val(self, val):
1619
self.val = val
1720

@@ -35,6 +38,9 @@ def set_val(self, val):
3538
spines[:].set_val('y')
3639
assert all(spine.val == 'y' for spine in spines.values())
3740

41+
spines[:].set(foo='bar')
42+
assert all(spine.foo == 'bar' for spine in spines.values())
43+
3844
with pytest.raises(AttributeError, match='foo'):
3945
spines.foo
4046
with pytest.raises(KeyError, match='foo'):

0 commit comments

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