PieGlyph Class#
The pie_glyph module provides the PieGlyph class for categorical pie
charts — one wedge per category from a (categories, values) pair, sized by
each value's share of the total and coloured from the shared palette system.
Negative or all-zero values have no meaningful pie representation and are
rejected.
Class Documentation#
cleopatra.glyphs.stats.pie_glyph.PieGlyph
#
Bases: Glyph
Visualization class for a categorical pie chart.
Draws one wedge per category from a (categories, values) pair, sized by
each value's share of the total and coloured from the shared palette
system. Negative or all-zero values have no meaningful pie representation
and are rejected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
categories
|
Sequence
|
Sequence of category labels (coerced to |
required |
values
|
Any
|
1-D sequence/array of wedge sizes, one per category. |
required |
colors
|
Sequence | None
|
Optional explicit per-category colours (length must equal the number of categories). Default None draws from the palette. |
None
|
ax
|
Axes | None
|
Pre-existing axes to draw on. Default None. |
None
|
fig
|
Figure | None
|
Pre-existing figure. Default None. |
None
|
**kwargs
|
Any
|
Construction-time overrides for |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A pie with a category->colour legend instead of wedge labels:
See Also
cleopatra.glyphs.stats.bar_glyph.BarGlyph: The same data as a bar chart.
Source code in src/cleopatra/glyphs/stats/pie_glyph.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
plot(ax=None, title=None, colors=None, autopct=_UNSET, add_legend=None, compose=False)
#
Draw the categorical pie chart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
Axes to draw on. Falls back to the axes supplied at construction, otherwise a new figure/axes is created. |
None
|
title
|
str | None
|
Plot title. Overrides |
None
|
colors
|
Sequence | None
|
Per-category colours for this call (length must equal the number of categories). Defaults to the colours given at construction, else the palette. |
None
|
autopct
|
str | None | _Unset
|
Per-wedge percentage format for this call. Defaults to the
|
_UNSET
|
add_legend
|
bool | None
|
Draw a disjoint category->colour legend instead of
labelling the wedges. Defaults to None, which keeps the
|
None
|
compose
|
bool
|
Draw over whatever is already on the axes instead of
replacing it, by default |
False
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes, list[Wedge]]
|
tuple[Figure, Axes, list[Wedge]]: The figure, the axes, and the list of wedge patches (one per category). |
Examples:
- Equal values give equal-angle wedges:
Source code in src/cleopatra/glyphs/stats/pie_glyph.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
Examples#
Pie with per-wedge percentage labels#
from cleopatra.glyphs.stats.pie_glyph import PieGlyph
glyph = PieGlyph(["a", "b", "c"], [3.0, 1.0, 2.0])
fig, ax, wedges = glyph.plot(title="Share by category")