Container for the artists of bar plots (e.g. created by `.Axes.bar`). The container can be treated as a tuple of the *patches* themselves. Additionally, you can access these and further parameters by the attributes. Attributes ---------- patches : list of :class:`~matp
| 40 | |
| 41 | |
| 42 | class BarContainer(Container): |
| 43 | """ |
| 44 | Container for the artists of bar plots (e.g. created by `.Axes.bar`). |
| 45 | |
| 46 | The container can be treated as a tuple of the *patches* themselves. |
| 47 | Additionally, you can access these and further parameters by the |
| 48 | attributes. |
| 49 | |
| 50 | Attributes |
| 51 | ---------- |
| 52 | patches : list of :class:`~matplotlib.patches.Rectangle` |
| 53 | The artists of the bars. |
| 54 | |
| 55 | errorbar : None or :class:`~matplotlib.container.ErrorbarContainer` |
| 56 | A container for the error bar artists if error bars are present. |
| 57 | *None* otherwise. |
| 58 | |
| 59 | datavalues : None or array-like |
| 60 | The underlying data values corresponding to the bars. |
| 61 | |
| 62 | orientation : {'vertical', 'horizontal'}, default: None |
| 63 | If 'vertical', the bars are assumed to be vertical. |
| 64 | If 'horizontal', the bars are assumed to be horizontal. |
| 65 | |
| 66 | """ |
| 67 | |
| 68 | def __init__(self, patches, errorbar=None, *, datavalues=None, |
| 69 | orientation=None, **kwargs): |
| 70 | self.patches = patches |
| 71 | self.errorbar = errorbar |
| 72 | self.datavalues = datavalues |
| 73 | self.orientation = orientation |
| 74 | super().__init__(patches, **kwargs) |
| 75 | |
| 76 | @property |
| 77 | def bottoms(self): |
| 78 | """ |
| 79 | Return the values at the lower end of the bars. |
| 80 | |
| 81 | .. versionadded:: 3.11 |
| 82 | """ |
| 83 | if self.orientation == 'vertical': |
| 84 | return [p.get_y() for p in self.patches] |
| 85 | elif self.orientation == 'horizontal': |
| 86 | return [p.get_x() for p in self.patches] |
| 87 | else: |
| 88 | raise ValueError("orientation must be 'vertical' or 'horizontal'.") |
| 89 | |
| 90 | @property |
| 91 | def tops(self): |
| 92 | """ |
| 93 | Return the values at the upper end of the bars. |
| 94 | |
| 95 | .. versionadded:: 3.11 |
| 96 | """ |
| 97 | if self.orientation == 'vertical': |
| 98 | return [p.get_y() + p.get_height() for p in self.patches] |
| 99 | elif self.orientation == 'horizontal': |
no outgoing calls
no test coverage detected
searching dependent graphs…