Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 877d977

Browse files
committed
Support spine.set() in SpinesProxy.
Artist.set() is a convenient way to set multiple properties at once; it seems reasonable to also support it in SpinesProxy.
1 parent 10e8bf1 commit 877d977

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed
Lines 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

Lines 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

Lines 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)