MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / ArtistInspector

Class ArtistInspector

lib/matplotlib/artist.py:1490–1789  ·  view source on GitHub ↗

A helper class to inspect an `~matplotlib.artist.Artist` and return information about its settable properties and their current values.

Source from the content-addressed store, hash-verified

1488
1489
1490class ArtistInspector:
1491 """
1492 A helper class to inspect an `~matplotlib.artist.Artist` and return
1493 information about its settable properties and their current values.
1494 """
1495
1496 def __init__(self, o):
1497 r"""
1498 Initialize the artist inspector with an `Artist` or an iterable of
1499 `Artist`\s. If an iterable is used, we assume it is a homogeneous
1500 sequence (all `Artist`\s are of the same type) and it is your
1501 responsibility to make sure this is so.
1502 """
1503 if not isinstance(o, Artist):
1504 if np.iterable(o):
1505 o = list(o)
1506 if len(o):
1507 o = o[0]
1508
1509 self.oorig = o
1510 if not isinstance(o, type):
1511 o = type(o)
1512 self.o = o
1513
1514 self.aliasd = self.get_aliases()
1515
1516 def get_aliases(self):
1517 """
1518 Get a dict mapping property fullnames to sets of aliases for each alias
1519 in the :class:`~matplotlib.artist.ArtistInspector`.
1520
1521 e.g., for lines::
1522
1523 {'markerfacecolor': {'mfc'},
1524 'linewidth' : {'lw'},
1525 }
1526 """
1527 names = [name for name in dir(self.o)
1528 if name.startswith(('set_', 'get_'))
1529 and callable(getattr(self.o, name))]
1530 aliases = {}
1531 for name in names:
1532 func = getattr(self.o, name)
1533 if not self.is_alias(func):
1534 continue
1535 propname = re.search(f"`({name[:4]}.*)`", # get_.*/set_.*
1536 inspect.getdoc(func)).group(1)
1537 aliases.setdefault(propname[4:], set()).add(name[4:])
1538 return aliases
1539
1540 _get_valid_values_regex = re.compile(
1541 r"\n\s*(?:\.\.\s+)?ACCEPTS:\s*((?:.|\n)*?)(?:$|(?:\n\n))"
1542 )
1543
1544 def get_valid_values(self, attr):
1545 """
1546 Get the legal arguments for the setter associated with *attr*.
1547

Callers 5

propertiesMethod · 0.85
getpFunction · 0.85
setpFunction · 0.85
kwdocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…