Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/matplotlib/container.py : 43%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from matplotlib.artist import Artist
2import matplotlib.cbook as cbook
5class Container(tuple):
6 """
7 Base class for containers.
9 Containers are classes that collect semantically related Artists such as
10 the bars of a bar plot.
11 """
13 def __repr__(self):
14 return ("<{} object of {} artists>"
15 .format(type(self).__name__, len(self)))
17 def __new__(cls, *args, **kwargs):
18 return tuple.__new__(cls, args[0])
20 def __init__(self, kl, label=None):
21 self.eventson = False # fire events only if eventson
22 self._oid = 0 # an observer id
23 self._propobservers = {} # a dict from oids to funcs
24 self._remove_method = None
25 self.set_label(label)
27 def remove(self):
28 for c in cbook.flatten(
29 self, scalarp=lambda x: isinstance(x, Artist)):
30 if c is not None:
31 c.remove()
33 if self._remove_method:
34 self._remove_method(self)
36 def get_children(self):
37 return [child for child in cbook.flatten(self) if child is not None]
39 get_label = Artist.get_label
40 set_label = Artist.set_label
41 add_callback = Artist.add_callback
42 remove_callback = Artist.remove_callback
43 pchanged = Artist.pchanged
46class BarContainer(Container):
47 """
48 Container for the artists of bar plots (e.g. created by `.Axes.bar`).
50 The container can be treated as a tuple of the *patches* themselves.
51 Additionally, you can access these and further parameters by the
52 attributes.
54 Attributes
55 ----------
56 patches : list of :class:`~matplotlib.patches.Rectangle`
57 The artists of the bars.
59 errorbar : None or :class:`~matplotlib.container.ErrorbarContainer`
60 A container for the error bar artists if error bars are present.
61 *None* otherwise.
63 """
65 def __init__(self, patches, errorbar=None, **kwargs):
66 self.patches = patches
67 self.errorbar = errorbar
68 Container.__init__(self, patches, **kwargs)
71class ErrorbarContainer(Container):
72 """
73 Container for the artists of error bars (e.g. created by `.Axes.errorbar`).
75 The container can be treated as the *lines* tuple itself.
76 Additionally, you can access these and further parameters by the
77 attributes.
79 Attributes
80 ----------
81 lines : tuple
82 Tuple of ``(data_line, caplines, barlinecols)``.
84 - data_line : :class:`~matplotlib.lines.Line2D` instance of
85 x, y plot markers and/or line.
86 - caplines : tuple of :class:`~matplotlib.lines.Line2D` instances of
87 the error bar caps.
88 - barlinecols : list of :class:`~matplotlib.collections.LineCollection`
89 with the horizontal and vertical error ranges.
91 has_xerr, has_yerr : bool
92 ``True`` if the errorbar has x/y errors.
94 """
96 def __init__(self, lines, has_xerr=False, has_yerr=False, **kwargs):
97 self.lines = lines
98 self.has_xerr = has_xerr
99 self.has_yerr = has_yerr
100 Container.__init__(self, lines, **kwargs)
103class StemContainer(Container):
104 """
105 Container for the artists created in a :meth:`.Axes.stem` plot.
107 The container can be treated like a namedtuple ``(markerline, stemlines,
108 baseline)``.
110 Attributes
111 ----------
112 markerline : :class:`~matplotlib.lines.Line2D`
113 The artist of the markers at the stem heads.
115 stemlines : list of :class:`~matplotlib.lines.Line2D`
116 The artists of the vertical lines for all stems.
118 baseline : :class:`~matplotlib.lines.Line2D`
119 The artist of the horizontal baseline.
120 """
121 def __init__(self, markerline_stemlines_baseline, **kwargs):
122 """
123 Parameters
124 ----------
125 markerline_stemlines_baseline : tuple
126 Tuple of ``(markerline, stemlines, baseline)``.
127 ``markerline`` contains the `LineCollection` of the markers,
128 ``stemlines`` is a `LineCollection` of the main lines,
129 ``baseline`` is the `Line2D` of the baseline.
130 """
131 markerline, stemlines, baseline = markerline_stemlines_baseline
132 self.markerline = markerline
133 self.stemlines = stemlines
134 self.baseline = baseline
135 Container.__init__(self, markerline_stemlines_baseline, **kwargs)