LineGlyph Class#
The LineGlyph class wraps Axes.plot, Axes.bar, and Axes.fill_between for
line, bar, and band plots. y may be 1-D (a single series) or 2-D
(n_points, n_series) — line and bar draw one series per column. Styling
comes from the shared options (color_1, line_width, marker, linestyle,
alpha).
Class Documentation#
cleopatra.line_glyph.LineGlyph
#
Bases: Glyph
Visualization class for line, bar, and band plots.
Wraps Axes.plot, Axes.bar, and Axes.fill_between. y may be
1D (a single series) or 2D (line/bar draw one series per
column). Styling comes from the shared options (color_1,
line_width, marker, linestyle, alpha).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1D array of x-coordinates. |
required |
y
|
ndarray
|
y-values. 1D for a single series, or 2D |
required |
ax
|
Axes
|
Pre-existing axes to draw on. Default is None. |
None
|
fig
|
Figure
|
Pre-existing figure. Default is None. |
None
|
**kwargs
|
Override any key in |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the length of |
Examples:
- Read back the y-data of the drawn line:
Source code in src/cleopatra/line_glyph.py
49 50 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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
bar(ax=None, title=None, color=None, **kwargs)
#
Draw a bar chart of a single series with Axes.bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to draw on. Falls back to the construction axes or a new figure/axes. |
None
|
title
|
str | None
|
Plot title override. |
None
|
color
|
Bar colour. Defaults to the |
None
|
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
|
tuple[Figure, Axes, BarContainer]: The figure, the axes, and the bar container. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- One bar per x value:
Source code in src/cleopatra/line_glyph.py
fill_between(y2=0.0, ax=None, title=None, color=None, alpha=None, **kwargs)
#
Fill the band between y and y2 with Axes.fill_between.
Useful for envelopes and quantile spreads: y is the upper
curve and y2 the lower (a scalar baseline or a matching
array). Requires 1D y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y2
|
float | ndarray
|
Lower curve, scalar or array matching |
0.0
|
ax
|
Axes
|
Axes to draw on. Falls back to the construction axes or a new figure/axes. |
None
|
title
|
str | None
|
Plot title override. |
None
|
color
|
Fill colour. Defaults to the |
None
|
|
alpha
|
float | None
|
Fill transparency. Defaults to |
None
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
|
tuple[Figure, Axes, PolyCollection]: The figure, the axes, and the filled band collection. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- Band between an upper curve and a scalar baseline:
Source code in src/cleopatra/line_glyph.py
line(ax=None, title=None, label=None, color=None, **kwargs)
#
Draw line/marker series with Axes.plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to draw on. Falls back to the construction axes or a new figure/axes. |
None
|
title
|
str | None
|
Plot title override. |
None
|
label
|
str | list[str] | None
|
Legend label(s); a single string for 1D |
None
|
color
|
Line colour. Defaults to the |
None
|
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
|
tuple[Figure, Axes, list[Line2D]]: The figure, the axes, and the list of drawn lines (one per series). |
Examples:
- Two series produce two lines:
Source code in src/cleopatra/line_glyph.py
Examples#
Line plot (single and multi-series)#
import numpy as np
from cleopatra.line_glyph import LineGlyph
x = np.linspace(0, 2 * np.pi, 100)
# single series
fig, ax, lines = LineGlyph(x, np.sin(x)).line(title="sin(x)")
# multiple series — one column per line
y = np.column_stack([np.sin(x), np.cos(x)])
fig, ax, lines = LineGlyph(x, y).line(label=["sin", "cos"])
ax.legend()
Bar chart#
import numpy as np
from cleopatra.line_glyph import LineGlyph
x = np.arange(5)
fig, ax, bars = LineGlyph(x, np.array([3.0, 5.0, 2.0, 8.0, 4.0])).bar(title="Counts")