r""" The container of all `.Spine`\s in an Axes. The interface is dict-like mapping names (e.g. 'left') to `.Spine` objects. Additionally, it implements some pandas.Series-like features like accessing elements by attribute:: spines['top'].set_visible(False) spines.t
| 537 | |
| 538 | |
| 539 | class Spines(MutableMapping): |
| 540 | r""" |
| 541 | The container of all `.Spine`\s in an Axes. |
| 542 | |
| 543 | The interface is dict-like mapping names (e.g. 'left') to `.Spine` objects. |
| 544 | Additionally, it implements some pandas.Series-like features like accessing |
| 545 | elements by attribute:: |
| 546 | |
| 547 | spines['top'].set_visible(False) |
| 548 | spines.top.set_visible(False) |
| 549 | |
| 550 | Multiple spines can be addressed simultaneously by passing a list:: |
| 551 | |
| 552 | spines[['top', 'right']].set_visible(False) |
| 553 | |
| 554 | Use an open slice to address all spines:: |
| 555 | |
| 556 | spines[:].set_visible(False) |
| 557 | |
| 558 | The latter two indexing methods will return a `SpinesProxy` that broadcasts all |
| 559 | ``set_*()`` and ``set()`` calls to its members, but cannot be used for any other |
| 560 | operation. |
| 561 | """ |
| 562 | def __init__(self, **kwargs): |
| 563 | self._dict = kwargs |
| 564 | |
| 565 | @classmethod |
| 566 | def from_dict(cls, d): |
| 567 | return cls(**d) |
| 568 | |
| 569 | def __getstate__(self): |
| 570 | return self._dict |
| 571 | |
| 572 | def __setstate__(self, state): |
| 573 | self.__init__(**state) |
| 574 | |
| 575 | def __getattr__(self, name): |
| 576 | try: |
| 577 | return self._dict[name] |
| 578 | except KeyError: |
| 579 | raise AttributeError( |
| 580 | f"'Spines' object does not contain a '{name}' spine") |
| 581 | |
| 582 | def __getitem__(self, key): |
| 583 | if isinstance(key, list): |
| 584 | unknown_keys = [k for k in key if k not in self._dict] |
| 585 | if unknown_keys: |
| 586 | raise KeyError(', '.join(unknown_keys)) |
| 587 | return SpinesProxy({k: v for k, v in self._dict.items() |
| 588 | if k in key}) |
| 589 | if isinstance(key, tuple): |
| 590 | raise ValueError('Multiple spines must be passed as a single list') |
| 591 | if isinstance(key, slice): |
| 592 | if key.start is None and key.stop is None and key.step is None: |
| 593 | return SpinesProxy(self._dict) |
| 594 | else: |
| 595 | raise ValueError( |
| 596 | 'Spines does not support slicing except for the fully ' |
no outgoing calls
searching dependent graphs…