File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
Expand file tree Collapse file tree 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):
479479
480480class 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 ):
Original file line number Diff line number Diff 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' ):
You can’t perform that action at this time.
0 commit comments