File tree 3 files changed +13
-4
lines changed
Filter options
3 files changed +13
-4
lines changed
Original file line number Diff line number Diff line change
1
+ ``SpinesProxy `` now supports calling the ``set() `` method
2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3
+ One can now call e.g. ``ax.spines[:].set(visible=False) ``.
Original file line number Diff line number Diff line change @@ -479,7 +479,7 @@ def set_color(self, c):
479
479
480
480
class SpinesProxy :
481
481
"""
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`.
483
483
484
484
The proxy cannot be used for any other operations on its members.
485
485
@@ -493,7 +493,7 @@ def __init__(self, spine_dict):
493
493
def __getattr__ (self , name ):
494
494
broadcast_targets = [spine for spine in self ._spine_dict .values ()
495
495
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 :
497
497
raise AttributeError (
498
498
f"'SpinesProxy' object has no attribute '{ name } '" )
499
499
@@ -531,8 +531,8 @@ class Spines(MutableMapping):
531
531
532
532
spines[:].set_visible(False)
533
533
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
536
536
operation.
537
537
"""
538
538
def __init__ (self , ** kwargs ):
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ class SpineMock:
12
12
def __init__ (self ):
13
13
self .val = None
14
14
15
+ def set (self , ** kwargs ):
16
+ vars (self ).update (kwargs )
17
+
15
18
def set_val (self , val ):
16
19
self .val = val
17
20
@@ -35,6 +38,9 @@ def set_val(self, val):
35
38
spines [:].set_val ('y' )
36
39
assert all (spine .val == 'y' for spine in spines .values ())
37
40
41
+ spines [:].set (foo = 'bar' )
42
+ assert all (spine .foo == 'bar' for spine in spines .values ())
43
+
38
44
with pytest .raises (AttributeError , match = 'foo' ):
39
45
spines .foo
40
46
with pytest .raises (KeyError , match = 'foo' ):
You can’t perform that action at this time.
0 commit comments