VectorGlyph Class#
The VectorGlyph class renders a 2-D (u, v) vector field over (x, y)
positions as arrows (quiver), wind barbs (barbs), or streamlines
(streamplot). The artist is coloured by the per-vector magnitude
hypot(u, v) through the shared scalar-mapping pipeline, with a matching
colorbar.
Class Documentation#
cleopatra.vector_glyph.VectorGlyph
#
Bases: Glyph
Visualization class for 2D vector fields.
Renders a (u, v) vector field over (x, y) positions as arrows,
wind barbs, or streamlines, with the artist coloured by the vector
magnitude hypot(u, v) through the shared scalar-mapping pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
x-coordinates of the vector positions. |
required |
y
|
ndarray
|
y-coordinates of the vector positions. |
required |
u
|
ndarray
|
x-components of the vectors. Must broadcast against |
required |
v
|
ndarray
|
y-components of the vectors. Must broadcast against |
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 |
{}
|
Examples:
- Build a field and inspect the stored magnitude:
See Also
cleopatra.glyph.Glyph._prepare_scalar_mapping: Shared norm/colorbar/ticks pipeline used to colour by magnitude.
Source code in src/cleopatra/vector_glyph.py
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 | |
magnitude
property
#
Per-vector magnitude hypot(u, v) used for colour mapping.
add_key(im, x=0.9, y=1.02, value=10.0, label=None, labelpos='E', **kwargs)
#
Add a reference-arrow key to a quiver plot.
Wraps Axes.quiverkey to draw a sample arrow of known length
with a text label, the standard legend for a quiver field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im
|
The |
required | |
x
|
float
|
Key x-position in axes fraction coordinates. Default is 0.9. |
0.9
|
y
|
float
|
Key y-position in axes fraction coordinates. Default is 1.02. |
1.02
|
value
|
float
|
The reference vector length the key represents. Default is 10.0. |
10.0
|
label
|
str | None
|
Text drawn beside the key. Default is |
None
|
labelpos
|
str
|
Side of the arrow for the label ( |
'E'
|
**kwargs
|
Forwarded to |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
QuiverKey |
QuiverKey
|
The created key artist. |
Examples:
- Add a 5 m/s reference key to a quiver:
>>> import numpy as np >>> from cleopatra.vector_glyph import VectorGlyph >>> x, y = np.meshgrid(np.arange(3), np.arange(3)) >>> u = np.ones_like(x, dtype=float) >>> v = np.ones_like(y, dtype=float) >>> glyph = VectorGlyph(x, y, u, v) >>> fig, ax, im = glyph.plot(kind="quiver") >>> key = glyph.add_key(im, value=5.0, label="5 m/s") >>> key.text.get_text() '5 m/s'
Source code in src/cleopatra/vector_glyph.py
plot(kind='quiver', ax=None, title=None, add_colorbar=None)
#
Render the vector field, coloured by magnitude.
Dispatches to Axes.quiver, Axes.barbs, or Axes.streamplot
based on kind. The colour scale, norm, ticks, and colorbar are
resolved from the magnitude via _prepare_scalar_mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
One of |
'quiver'
|
ax
|
Axes
|
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
|
add_colorbar
|
bool | None
|
Override the |
None
|
Returns:
| Type | Description |
|---|---|
|
tuple[Figure, Axes, Any]: The figure, the axes, and the
mappable artist (the |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
- A barbs plot returns the Barbs mappable with the magnitude
array:
>>> import numpy as np >>> from cleopatra.vector_glyph import VectorGlyph >>> x, y = np.meshgrid(np.arange(3), np.arange(3)) >>> u = np.full_like(x, 2.0, dtype=float) >>> v = np.zeros_like(y, dtype=float) >>> glyph = VectorGlyph(x, y, u, v) >>> fig, ax, im = glyph.plot(kind="barbs") >>> float(im.get_array().max()) 2.0 - An unknown kind raises ValueError:
>>> import numpy as np >>> from cleopatra.vector_glyph import VectorGlyph >>> x, y = np.meshgrid(np.arange(2), np.arange(2)) >>> glyph = VectorGlyph(x, y, np.ones_like(x), np.ones_like(y)) >>> glyph.plot(kind="spirograph") Traceback (most recent call last): ... ValueError: unknown vector kind 'spirograph'; expected one of ...
Source code in src/cleopatra/vector_glyph.py
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 | |
Examples#
Arrows (quiver)#
import numpy as np
from cleopatra.vector_glyph import VectorGlyph
x, y = np.meshgrid(np.linspace(0, 1, 8), np.linspace(0, 1, 8))
u, v = np.cos(x * np.pi), np.sin(y * np.pi)
vg = VectorGlyph(x, y, u, v)
fig, ax, artist = vg.plot(kind="quiver", title="Vector field")