Plotting¶
Publication figures from a FieldDataset. Requires the plot extra
(matplotlib); the 3D surface in pypic.plotting.pyvista requires 3d.
Beyond field slices and comparisons, this subpackage covers line plots and time series, kymographs, quiver and streamline overlays, scatter plots, power spectra, Poincaré sections, and a theme system with annotation helpers (badges, planets, contours, insets, legends).
Themes¶
set_theme / use_theme select a bundled theme; available_themes lists
them. load_theme and save_theme read and write theme TOML, and
export_themes emits the bundle that the webpic viewer consumes.
Themes are looked up in $PYPIC_THEME_DIR when that variable is set,
otherwise under $XDG_CONFIG_HOME/pypic/themes (falling back to
~/.config/pypic/themes), and finally the themes bundled with the package.
plotting
¶
Plotting utilities for pypic field data.
Requires matplotlib (optional dependency). Install with::
pip install "pypic-plasma[plot]"
This module can be imported for type checking without matplotlib installed.
Actual plotting functions call ensure_matplotlib() at entry.
BadgeLoc = Literal['upper left', 'upper right', 'lower left', 'lower right', 'upper center']
¶
Canonical overlay location strings shared by both plotting backends.
Space-separated form (e.g. "upper right") matches matplotlib's own
AnchoredOffsetbox convention. The legacy pyvista underscore form
("upper_right") is still accepted by _normalize_loc for
backward compatibility.
ThemeArg = PlotTheme | str | None
¶
Accepted type for the theme parameter across all plotting functions.
LegendEntry
dataclass
¶
One row in a vector legend: a sample line and its label.
Source code in src/pypic/plotting/_badge.py
456 457 458 459 460 461 462 463 464 | |
PlotTheme
dataclass
¶
Immutable collection of matplotlib styling for pypic plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Human-readable theme name. |
required |
rcparams
|
Mapping[str, Any]
|
Full set of matplotlib rcParams to apply (must not contain
|
required |
sequential_cmaps
|
tuple[str, ...]
|
Colormap preference list for positive-definite fields (first is default). |
('inferno',)
|
diverging_cmaps
|
tuple[str, ...]
|
Colormap preference list for signed fields (first is default). |
('RdBu_r',)
|
grid_color
|
tuple[float, float, float, float]
|
RGBA color for grid lines; the alpha channel carries the
built-in opacity (default |
(0.0, 0.0, 0.0, 0.08)
|
color_cycle
|
tuple[str, ...]
|
Hex color wheel for sequential visual elements (lines, scatter,
categories). Built into |
()
|
Source code in src/pypic/plotting/styles.py
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 | |
sequential_cmap
property
¶
Default sequential colormap (first in preference list).
diverging_cmap
property
¶
Default diverging colormap (first in preference list).
customize(**overrides)
¶
Return a new theme with selected fields overridden.
Pass any PlotTheme field name as a keyword argument.
Unknown keys with underscores are converted to matplotlib
rcParam keys and merged into rcparams
(figure_dpi=200 → "figure.dpi": 200).
Returns:
| Type | Description |
|---|---|
PlotTheme
|
|
Examples:
>>> t = get_theme()
>>> big = t.customize(font_title=16.0)
>>> big.font_title
16.0
>>> wide = t.customize(figsize_per_col=6.0)
>>> wide.figsize_per_col
6.0
Source code in src/pypic/plotting/styles.py
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 | |
add_badge(ax, text=None, *, step=None, time=None, time_units='', step_range=None, label=None, show_max=True, progress=None, variant=None, loc=None, fontsize=None, bar_color=None, bar_alpha=0.8, bar_width=None, bar_height=None, bg_color=None, bg_alpha=None, text_color=None, text_alpha=0.8, track_color=None)
¶
Add a status badge overlay to an axes.
Renders simulation step, time, or custom text as a rounded box. A progress bar is shown when step_range or progress is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes for the badge. |
required |
text
|
str
|
Direct custom text. When provided, step/time/label are ignored for text generation (but step_range/progress still drive the progress bar). |
None
|
step
|
int
|
Current simulation step number. |
None
|
time
|
float or str
|
Simulation time. A float is auto-formatted; a string is used
verbatim (e.g. |
None
|
time_units
|
str
|
Unit label appended to the time value (e.g. |
''
|
step_range
|
tuple[int, int]
|
|
None
|
label
|
str or None
|
Custom label prefix (e.g. |
None
|
show_max
|
bool
|
When |
True
|
progress
|
float or None
|
Explicit progress fraction (0.0 to 1.0). Overrides step_range auto-computation when both are given. |
None
|
variant
|
"darker", "lighter", "alt", or None
|
|
None
|
loc
|
BadgeLoc or None
|
Badge placement. |
None
|
fontsize
|
float
|
Font size for the status text. |
None
|
bar_color
|
str
|
Fill color for the progress bar. |
None
|
bar_alpha
|
float
|
Opacity of the progress bar fill. |
0.8
|
bar_width
|
float
|
Width of the progress bar in points. |
None
|
bar_height
|
float
|
Height of the progress bar in points. |
None
|
bg_color
|
str, tuple, or None
|
Box background color override. |
None
|
bg_alpha
|
float
|
Box background opacity. |
None
|
text_color
|
str, tuple, or None
|
Text color override. |
None
|
text_alpha
|
float
|
Text opacity (default 0.85 for subtle softening). |
0.8
|
track_color
|
str, tuple, or None
|
Progress bar track color override. |
None
|
Returns:
| Type | Description |
|---|---|
AnchoredOffsetbox
|
The badge artist added to the axes. |
Examples:
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> _ = add_badge(ax, step=42)
>>> _ = add_badge(ax, step=100, label="Cycle")
>>> _ = add_badge(ax, time="13:34")
>>> _ = add_badge(ax, "Harris sheet, δ = 0.5 d_i")
>>> plt.close(fig)
Source code in src/pypic/plotting/_badge.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
add_label(ax, label, *, variant=None, loc=None, fontsize=None, fontweight='bold', ha='left', bg_color=None, bg_alpha=None, text_color=None, text_alpha=0.8)
¶
Add a bold panel letter (a, b, c, ...) overlay to an axes.
Styled with the same rounded box as add_badge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
label
|
str
|
Panel label text (e.g. |
required |
variant
|
"darker", "lighter", "alt", or None
|
|
None
|
loc
|
BadgeLoc or None
|
Placement. |
None
|
fontsize
|
float
|
Label font size. |
None
|
fontweight
|
str
|
Font weight (default |
'bold'
|
bg_color
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
bg_alpha
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
text_color
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
text_alpha
|
float
|
Text opacity (default 0.85 for subtle softening). |
0.8
|
Returns:
| Type | Description |
|---|---|
AnchoredOffsetbox
|
|
Source code in src/pypic/plotting/_badge.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
add_legend(ax, entries, *, color=None, linewidth=1.0, entry_alpha=1.0, variant=None, loc=None, fontsize=None, sample_width=20, bg_color=None, bg_alpha=None, text_color=None, text_alpha=0.8)
¶
Add a vector legend overlay showing colored line samples with labels.
Each entry renders as a short line segment (using the entry's color,
linewidth, linestyle, alpha) next to its label text. Multiple entries
are stacked vertically. The box style matches add_badge.
For a single entry, pass a string label directly::
add_legend(ax, "J", color="white")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
entries
|
str, LegendEntry, or list[LegendEntry]
|
A field label string, a single entry, or multiple entries. |
required |
color
|
str or None
|
Line color when entries is a string. |
None
|
linewidth
|
float
|
Line width when entries is a string. |
1.0
|
entry_alpha
|
float
|
Line opacity when entries is a string. |
1.0
|
variant
|
"darker", "lighter", "alt", or None
|
|
None
|
loc
|
BadgeLoc or None
|
Placement. |
None
|
fontsize
|
float
|
Label font size. |
None
|
sample_width
|
float
|
Width of the sample line in points. |
20
|
bg_color
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
bg_alpha
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
text_color
|
str | tuple[float, ...] | None
|
Color overrides; same semantics as |
None
|
text_alpha
|
float
|
Text opacity (default 0.85 for subtle softening). |
0.8
|
Returns:
| Type | Description |
|---|---|
AnchoredOffsetbox
|
|
Source code in src/pypic/plotting/_badge.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
add_colorbar(fig, ax, mappable, label, *, extend='both', extremes='semi')
¶
Add a colorbar with styled over/under extensions and subtle outline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
Figure the colorbar is drawn on. |
required |
ax
|
Axes
|
Axes the colorbar is attached to. |
required |
mappable
|
ScalarMappable
|
The image or collection the colorbar describes. |
required |
label
|
str
|
Colorbar label text. |
required |
extend
|
str
|
Which ends to draw out-of-range indicators on:
|
'both'
|
extremes
|
"semi", "transparent", "darken", or None
|
|
'semi'
|
Returns:
| Type | Description |
|---|---|
Colorbar
|
The attached colorbar, already styled. |
Notes
Colors for the outline, ticks, and label are read from the active matplotlib rcParams so that custom themes propagate automatically.
Source code in src/pypic/plotting/_colorbar.py
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 | |
add_inset_colorbar(ax, mappable, label='', *, loc=None, variant=None, width=0.3, height=0.02, pad=None, extend='both', extremes='semi', n_ticks=3, ticks=None, fontsize=None, bg_color=None, bg_alpha=None, text_color=None, text_alpha=0.8)
¶
Add a horizontal colorbar rendered inside the plot axes.
Uses ax.inset_axes() for the colorbar with a rounded background
patch. Visually matches the badge style from
add_badge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
mappable
|
object
|
A |
required |
label
|
str
|
Colorbar label text. |
''
|
loc
|
BadgeLoc or None
|
Inset placement. |
None
|
variant
|
"darker", "lighter", "alt", or None
|
|
None
|
width
|
float
|
Bar width as a fraction of axes width. |
0.3
|
height
|
float
|
Bar height as a fraction of axes height. |
0.02
|
pad
|
float
|
Padding from axes edge as a fraction. |
None
|
extend
|
str
|
Colorbar extension ( |
'both'
|
n_ticks
|
int
|
Maximum number of colorbar tick intervals. |
3
|
fontsize
|
float
|
Font size for tick labels and colorbar label. |
None
|
bg_color
|
str, tuple, or None
|
Background box color override. |
None
|
bg_alpha
|
float
|
Background box opacity. |
None
|
text_color
|
str, tuple, or None
|
Tick and label color override. |
None
|
text_alpha
|
float
|
Text opacity (default 0.85 for subtle softening). |
0.8
|
ticks
|
Sequence[float] or None
|
Explicit tick positions. |
None
|
Returns:
| Type | Description |
|---|---|
Colorbar
|
|
Source code in src/pypic/plotting/_colorbar.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
auto_clim(values, *, positive_definite)
¶
Compute auto color limits using 3\(\sigma\) from the median.
Positive-definite fields get (0, round_nice(median + 3*sigma)).
Signed fields get (-spread, spread) where
spread = round_nice(3*sigma), symmetric around zero so the
colormap's zero-crossing aligns with physical zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
FloatArray
|
Field values (may contain NaN). |
required |
positive_definite
|
bool
|
Whether the field is positive-definite. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in src/pypic/plotting/_colormaps.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
round_nice(value)
¶
Round a positive value to the nearest 1-2-5 \(\times 10^n\) step.
The 1-2-5 sequence (..., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, ...) produces clean colorbar tick labels and avoids awkward intermediate values like 3 or 7.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
Positive value to round. Zero returns 0. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Examples:
>>> round_nice(0.7)
0.5
>>> round_nice(3.5)
5.0
>>> round_nice(150.0)
200.0
Source code in src/pypic/plotting/_colormaps.py
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 | |
available_themes()
¶
Return all available themes from user and package directories.
User themes override bundled themes of the same name. Each call reads fresh from disk.
Returns:
| Type | Description |
|---|---|
dict[str, PlotTheme]
|
Mapping from theme name to loaded theme. |
Source code in src/pypic/plotting/_theme_io.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
export_themes(directory=None, *, overwrite=False)
¶
Copy bundled themes to a directory for editing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path | None
|
Target directory. |
None
|
overwrite
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
The directory themes were written to. |
Source code in src/pypic/plotting/_theme_io.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
load_theme(path)
¶
Load a PlotTheme from a TOML file.
Only name and [colors] (with at least background and
text) are required. All other keys fall back to PlotTheme
defaults, and sections other tools own ([webpic], ...) are
ignored.
Raises:
| Type | Description |
|---|---|
ValueError
|
If a key holds the wrong TOML type (a string where a number or boolean belongs, ...). |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str or Path
|
Path to the |
required |
Returns:
| Type | Description |
|---|---|
PlotTheme
|
|
Examples:
>>> from pypic.plotting._theme_io import _bundled_theme_dir, load_theme
>>> t = load_theme(_bundled_theme_dir() / "dark.toml")
>>> t.name
'dark'
Source code in src/pypic/plotting/_theme_io.py
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 | |
save_theme(theme, path)
¶
Save a PlotTheme to a TOML file.
The output uses the cross-project schema with RGBA color tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
PlotTheme
|
Theme to serialize. |
required |
path
|
str or Path
|
Output file path. |
required |
Examples:
>>> import tempfile
>>> from pathlib import Path
>>> from pypic.plotting._theme_io import _bundled_theme_dir, load_theme, save_theme
>>> theme = load_theme(_bundled_theme_dir() / "light.toml")
>>> with tempfile.TemporaryDirectory() as tmp:
... out = Path(tmp) / "light.toml"
... save_theme(theme, out)
... load_theme(out).name == theme.name
True
Source code in src/pypic/plotting/_theme_io.py
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 301 | |
add_circle(ax, radius, center=(0.0, 0.0), *, label=None, label_position=45.0, color=None, alpha=0.6, linestyle='--', linewidth=0.8, fontsize=None, text_alpha=0.9, variant=None, zorder=5)
¶
Draw a reference circle with an optional radius label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
radius
|
float
|
Circle radius in data units. |
required |
center
|
tuple[float, float]
|
Circle center in data coordinates. |
(0.0, 0.0)
|
label
|
str
|
Text placed on the circle perimeter (e.g. |
None
|
label_position
|
float
|
Angle in degrees (CCW from +x) where the label sits. |
45.0
|
color
|
str
|
Line color. Defaults to the theme's grid color at higher opacity. |
None
|
alpha
|
float
|
Line opacity. |
0.6
|
linestyle
|
str
|
Line style ( |
'--'
|
linewidth
|
float
|
Line width. |
0.8
|
fontsize
|
float | None
|
Label font size. |
None
|
text_alpha
|
float
|
Label opacity. |
0.9
|
variant
|
'alt'
|
Overlay variant for label styling. |
"alt"
|
zorder
|
int
|
Drawing order. |
5
|
Returns:
| Type | Description |
|---|---|
Circle
|
The circle patch. |
Source code in src/pypic/plotting/annotations.py
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 | |
add_planet(ax, center=(0.0, 0.0), radius=1.0, *, sun_direction='left', day_color='#f0f0f0', night_color='#1a1a2e', edgecolor='#888888', linewidth=0.5, zorder=10)
¶
Draw a day/night planet marker at a data-space position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
center
|
tuple[float, float]
|
Planet center in data coordinates. |
(0.0, 0.0)
|
radius
|
float
|
Planet radius in data units. |
1.0
|
sun_direction
|
('left', 'right', 'up', 'down')
|
Which side of the plot the Sun is on. |
"left"
|
day_color
|
str
|
Face colors for the sunlit and dark hemispheres. |
'#f0f0f0'
|
night_color
|
str
|
Face colors for the sunlit and dark hemispheres. |
'#f0f0f0'
|
edgecolor
|
str
|
Border color for both semicircles. |
'#888888'
|
linewidth
|
float
|
Border width. |
0.5
|
zorder
|
int
|
Drawing order (default 10, above most plot elements). |
10
|
Returns:
| Type | Description |
|---|---|
tuple[Wedge, Wedge]
|
The (day, night) wedge patches. |
Source code in src/pypic/plotting/annotations.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_comparison(data_a, data_b, field, *, plane=None, units=None, coord_units=None, theme=None, cmap=None, diff_cmap=None, vmin=None, vmax=None, diff_vmin=None, diff_vmax=None, labels=('A', 'B'), alpha=1.0, symmetric=None, log_scale=False, symlog=False, linthresh=None, step=None, time=None, colorbar=True, extremes='semi', show_error=False, ax=None, save=None, figsize=None, title=None)
¶
Three-panel comparison: dataset A, dataset B, and their difference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_a
|
FieldDataset
|
Two datasets to compare (must share compatible grids). |
required |
data_b
|
FieldDataset
|
Two datasets to compare (must share compatible grids). |
required |
field
|
str
|
Field name — canonical, alias, or derived. |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
units
|
str | None
|
Display units for field values. |
None
|
coord_units
|
str | None
|
Display units for coordinate axes. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | Colormap | None
|
Override colormap for A/B panels. |
None
|
diff_cmap
|
str | Colormap | None
|
Override colormap for difference panel. Defaults to diverging. |
None
|
vmin
|
float | None
|
Color limits for A/B panels. |
None
|
vmax
|
float | None
|
Color limits for A/B panels. |
None
|
diff_vmin
|
float | None
|
Color limits for the difference panel. |
None
|
diff_vmax
|
float | None
|
Color limits for the difference panel. |
None
|
labels
|
tuple[str, str]
|
Panel labels for A and B. |
('A', 'B')
|
alpha
|
float
|
Mesh transparency (0 = invisible, 1 = opaque). |
1.0
|
symmetric
|
bool | None
|
Force symmetric color limits on A/B panels. |
None
|
log_scale
|
bool
|
Use logarithmic color mapping on A/B panels. The difference panel always uses linear scale. Ignored when symmetric is active. |
False
|
step
|
int | None
|
Timestep number for the suptitle. |
None
|
time
|
float | None
|
Simulation time for the suptitle. |
None
|
colorbar
|
bool or 'inset'
|
|
True
|
extremes
|
"semi", "transparent", "darken", or None
|
Colorbar out-of-range indicator style. |
'semi'
|
show_error
|
bool
|
When |
False
|
ax
|
tuple[Axes, Axes, Axes] or None
|
Existing axes for A, B and the difference, in that order; the
figure they belong to is then left to the caller to lay out.
|
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. Defaults to |
None
|
title
|
str | None
|
Override auto-generated suptitle. |
None
|
data_a
|
FieldDataset
|
Left-hand dataset (panel A). |
required |
data_b
|
FieldDataset
|
Right-hand dataset (panel B); must share A's grid. |
required |
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
diff_vmin
|
float or None
|
Lower color limit for the difference panel. |
None
|
diff_vmax
|
float or None
|
Upper color limit for the difference panel. |
None
|
symlog
|
bool
|
Use a symmetric-log color scale, for signed fields spanning several decades. |
False
|
linthresh
|
float or None
|
Linear threshold for |
None
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, dict[str, Axes]]
|
Figure and dict with keys |
Source code in src/pypic/plotting/comparison.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_cross_section(data, field, *, cut_axis, cut_index=None, plane=None, units=None, coord_units=None, theme=None, cmap=None, vmin=None, vmax=None, alpha=1.0, symmetric=None, log_scale=False, title=None, step=None, time=None, colorbar=True, extremes='semi', cut_color=None, cut_linestyle='--', ax=None, save=None, figsize=None)
¶
Two-panel figure: 2D field slice with a 1D cut profile below.
The top panel shows the scalar field via plot_field_slice
with a dashed line marking the cut location. The bottom panel
shows the 1D profile along that cut.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field
|
str
|
Scalar field name. |
required |
cut_axis
|
str
|
Axis along which to extract the 1D profile (e.g. |
required |
cut_index
|
int | None
|
Index on the perpendicular axis where the cut is made.
|
None
|
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
units
|
str | None
|
Display units for field values. |
None
|
coord_units
|
str, tuple[str, str], or None
|
Display units for coordinate axes. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | Colormap | None
|
Override colormap. |
None
|
vmin
|
float | None
|
Color limits. |
None
|
vmax
|
float | None
|
Color limits. |
None
|
log_scale
|
bool
|
Logarithmic color mapping. |
False
|
title
|
str | None
|
Override auto-generated title. |
None
|
step
|
int | None
|
Timestep number. |
None
|
time
|
float | None
|
Simulation time. |
None
|
colorbar
|
bool or 'inset'
|
Colorbar mode. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
Colorbar out-of-range indicator style. |
'semi'
|
cut_color
|
str or None
|
Color for the cut line marker on the 2D panel. |
None
|
cut_linestyle
|
str
|
Line style for the cut marker. |
'--'
|
ax
|
tuple[Axes, Axes] or None
|
Existing |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
alpha
|
float
|
Opacity of the field image, in |
1.0
|
symmetric
|
bool or None
|
Force symmetric color limits about zero. |
None
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, tuple[Axes, Axes]]
|
Figure and |
Source code in src/pypic/plotting/cross_section.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_kymograph(values, coords, times, *, label='', units=None, xlabel=None, ylabel=None, theme=None, cmap=None, vmin=None, vmax=None, symmetric=None, log_scale=False, title=None, ax=None, colorbar=True, extremes='semi', save=None, figsize=None)
¶
Plot a time-distance (kymograph) diagram.
Displays a 1D spatial profile at each timestep as a 2D color map, with the spatial coordinate on the x-axis and time on the y-axis. Common in reconnection, wave propagation, and shock studies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
FloatArray
|
2D array of shape |
required |
coords
|
FloatArray
|
1D spatial coordinate array of length |
required |
times
|
FloatArray
|
1D time array of length |
required |
label
|
str
|
Colorbar label (e.g. |
''
|
units
|
str | None
|
Units values are already in, appended to the colorbar label as
|
None
|
xlabel
|
str | None
|
X-axis label. |
None
|
ylabel
|
str | None
|
Y-axis label. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | None
|
Colormap override. |
None
|
vmin
|
float | None
|
Color limits. |
None
|
vmax
|
float | None
|
Color limits. |
None
|
symmetric
|
bool | None
|
Force symmetric color limits around zero. |
None
|
log_scale
|
bool
|
Use logarithmic color mapping. Ignored when symmetric. |
False
|
title
|
str | None
|
Axes title. |
None
|
ax
|
Axes | None
|
Existing axes. |
None
|
colorbar
|
bool or 'inset'
|
Colorbar mode. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
How to style values outside |
'semi'
|
save
|
str | None
|
Save figure to this path. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If values is not 2D or shapes are inconsistent. |
Source code in src/pypic/plotting/kymograph.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_line(data, field, *, axis=None, index=None, units=None, coord_units=None, theme=None, label=None, title=None, step=None, time=None, ax=None, save=None, figsize=None, **kwargs)
¶
Plot a 1D spatial profile of a field along one axis.
For 2D/3D data, other axes are sliced at the given index values (default: midplane). For 1D data, the single axis is used directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (1D, 2D, or 3D). |
required |
field
|
str
|
Field name — canonical, alias, or derived (e.g. |
required |
axis
|
str | None
|
Axis to plot along (e.g. |
None
|
index
|
dict[str, int] | None
|
Fix non-plot axes at these integer indices. |
None
|
units
|
str | None
|
Display units for field values (e.g. |
None
|
coord_units
|
str | None
|
Display units for the coordinate axis. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
label
|
str | None
|
Legend label. |
None
|
title
|
str | None
|
Override auto-generated title. |
None
|
step
|
int | None
|
Timestep number for the title. |
None
|
time
|
float | None
|
Simulation time for the title. |
None
|
ax
|
Axes | None
|
Existing axes to draw on. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/lines.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_line_comparison(datasets, field, *, axis=None, index=None, labels=None, units=None, coord_units=None, theme=None, title=None, ax=None, save=None, figsize=None, **kwargs)
¶
Compare 1D profiles of the same field from multiple datasets.
Overlays one line per dataset with automatic color cycling and legend. Useful for comparing simulation runs with different parameters or resolutions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
list[FieldDataset]
|
Datasets to compare (must share compatible axes). |
required |
field
|
str
|
Field name to plot from each dataset. |
required |
axis
|
str | None
|
Axis to plot along (required for 2D/3D data). |
None
|
index
|
dict[str, int] | None
|
Fix non-plot axes at these indices. |
None
|
labels
|
list[str] | None
|
Legend labels (one per dataset). |
None
|
units
|
str | None
|
Display units for field values. |
None
|
coord_units
|
str | None
|
Display units for the coordinate axis. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
title
|
str | None
|
Axes title. |
None
|
ax
|
Axes | None
|
Existing axes. |
None
|
save
|
str | None
|
Save figure to this path. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/lines.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
plot_lines(data, fields, *, axis=None, index=None, labels=None, units=None, coord_units=None, theme=None, title=None, step=None, time=None, ax=None, save=None, figsize=None, **kwargs)
¶
Plot multiple fields overlaid on the same axes.
Convenience wrapper around plot_line that handles axes
reuse, automatic color cycling, and legend display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset. |
required |
fields
|
list[str]
|
Field names to plot (one line per field). |
required |
axis
|
str | None
|
Axis to plot along (required for 2D/3D data). |
None
|
index
|
dict[str, int] | None
|
Fix non-plot axes at these indices. |
None
|
labels
|
list[str] | None
|
Legend labels. |
None
|
units
|
str | None
|
Display units for field values. |
None
|
coord_units
|
str | None
|
Display units for coordinate axis. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
title
|
str | None
|
Axes title. |
None
|
step
|
int | None
|
Timestep number for the title. |
None
|
time
|
float | None
|
Simulation time for the title. |
None
|
ax
|
Axes | None
|
Existing axes. |
None
|
save
|
str | None
|
Save figure to this path (and close). |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/lines.py
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 | |
plot_time_series(data, columns, *, x_column=None, theme=None, labels=None, title=None, xlabel=None, ylabel=None, ax=None, save=None, figsize=None, legend=True, **kwargs)
¶
Plot one or more columns from tabular data as time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
TabularData
|
Tabular data source (e.g. conserved quantities). |
required |
columns
|
str | list[str]
|
Column name(s) to plot. |
required |
x_column
|
str | None
|
Column for the x-axis. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
labels
|
list[str] | None
|
Legend labels. |
None
|
title
|
str | None
|
Axes title. |
None
|
xlabel
|
str | None
|
X-axis label. |
None
|
ylabel
|
str | None
|
Y-axis label. |
None
|
ax
|
Axes | None
|
Existing axes to draw on. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
legend
|
bool
|
Whether to show a legend (default |
True
|
**kwargs
|
Any
|
Passed to |
{}
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/lines.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
plot_field_grid(data, fields, *, ncols=3, plane=None, units=None, coord_units=None, theme=None, cmap=None, vmin=None, vmax=None, colorbar=True, extremes='semi', alpha=1.0, symmetric=None, log_scale=False, step=None, time=None, save=None, figsize=None, panel_labels=True, suptitle=None, ax=None)
¶
Plot multiple fields in an auto-arranged grid with panel labels.
Creates a figure with ceil(len(fields) / ncols) rows and
ncols columns. Each panel shows one field via
plot_field_slice, with optional (a), (b), (c)
labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
fields
|
list[str]
|
Field names to plot, one per panel. |
required |
ncols
|
int
|
Number of columns in the grid. |
3
|
plane
|
PlaneSelection | None
|
Plane selection for 3D data (applied to all panels). |
None
|
units
|
dict[str, str] | None
|
Per-field display units, keyed by field name. Fields not in the dict use code units. |
None
|
coord_units
|
str, tuple[str, str], or None
|
Coordinate axis units (shared across panels). |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str, Colormap, dict, or None
|
Colormap override. A single string or Colormap applies to all panels; a dict maps field names to per-field colormaps. |
None
|
vmin
|
float | None
|
Shared color limits across all panels. |
None
|
vmax
|
float | None
|
Shared color limits across all panels. |
None
|
colorbar
|
bool or 'inset'
|
Colorbar mode for each panel. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
Colorbar out-of-range indicator style. |
'semi'
|
log_scale
|
bool
|
Use logarithmic color mapping for all panels. |
False
|
step
|
int | None
|
Timestep number (shown in suptitle if suptitle is not set). |
None
|
time
|
float | None
|
Simulation time (shown in suptitle if suptitle is not set). |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
panel_labels
|
bool
|
Add |
True
|
suptitle
|
str | None
|
Figure super-title. |
None
|
ax
|
Sequence[Axes] or None
|
Existing axes, one per field in order; ncols and figsize are
then unused and the figure is left to the caller to lay out.
|
None
|
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
alpha
|
float
|
Opacity of the field image, in |
1.0
|
symmetric
|
bool or None
|
Force symmetric color limits about zero. |
None
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, list[Axes]]
|
Figure and flat list of axes (one per field). |
Source code in src/pypic/plotting/panels.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_poincare_section(section, *, ax=None, theme=None, color_by_seed=True, marker_size=2.0, alpha=0.7, title=None, save=None, figsize=None)
¶
Scatter the puncture cloud of a PoincareSection.
Each seed's punctures get a distinct color from the active theme's
cycle when color_by_seed is true — co-orbital points appear as
same-color closed curves (islands / KAM surfaces) and chaotic seeds
fill 2D regions in a single color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section
|
PoincareSection
|
Output of |
required |
ax
|
Axes | None
|
Existing axes. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
color_by_seed
|
bool
|
Cycle a distinct theme color per seed. When false, all punctures share one color (cleaner for very dense clouds). |
True
|
marker_size
|
float
|
Marker size in points². |
2.0
|
alpha
|
float
|
Point transparency. |
0.7
|
title
|
str | None
|
Axes title. Defaults to |
None
|
save
|
str or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/poincare.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_scatter(data, field_x, field_y, *, plane=None, color_field=None, units_x=None, units_y=None, color_units=None, theme=None, cmap=None, vmin=None, vmax=None, alpha=0.3, marker_size=1.0, density=False, bins=80, log_x=False, log_y=False, title=None, ax=None, colorbar=True, save=None, figsize=None)
¶
Scatter or density plot of two field quantities.
Plots every grid point's value of field_x against field_y. Useful for equation-of-state analysis (\(P\) vs \(\rho\)), anisotropy studies (\(P_\parallel\) vs \(P_\perp\)), and general correlation exploration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field_x
|
str
|
Field for the horizontal axis. |
required |
field_y
|
str
|
Field for the vertical axis. |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
color_field
|
str | None
|
Optional third field for point color (e.g. |
None
|
units_x
|
str | None
|
Display units for field_x. |
None
|
units_y
|
str | None
|
Display units for field_y. |
None
|
color_units
|
str | None
|
Display units for color_field. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | None
|
Colormap override for colored scatter or density mode. |
None
|
vmin
|
float | None
|
Color limits for color_field or the density counts. |
None
|
vmax
|
float | None
|
Color limits for color_field or the density counts. |
None
|
alpha
|
float
|
Point transparency (scatter mode only). |
0.3
|
marker_size
|
float
|
Marker size in points² (scatter mode only). |
1.0
|
density
|
bool
|
Use a hexbin density plot instead of a scatter plot. Better for large grids where individual points overlap heavily. |
False
|
bins
|
int
|
Hexbin grid size ( |
80
|
log_x
|
bool
|
Logarithmic x-axis. |
False
|
log_y
|
bool
|
Logarithmic y-axis. |
False
|
title
|
str | None
|
Axes title. |
None
|
ax
|
Axes | None
|
Existing axes. |
None
|
colorbar
|
bool
|
Show a colorbar when color_field is set or |
True
|
save
|
str | None
|
Save figure to this path. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/scatter.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
add_contours(ax, data, field, *, plane=None, units=None, levels=5, colors=None, linewidths=0.5, alpha=0.7, linestyles='solid', labels=False, label_fontsize=None, **kwargs)
¶
Add contour lines to existing axes from a scalar field.
Works as an overlay on plot_field_slice or any other 2D plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes (must already have coordinate limits set). |
required |
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field
|
str
|
Scalar field name for contouring. |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
units
|
str | None
|
Display units for field values. |
None
|
levels
|
int or list[float]
|
Number of contour levels, or explicit level values. |
5
|
colors
|
str, list[str], or None
|
Line color(s). |
None
|
linewidths
|
float
|
Contour line width. |
0.5
|
alpha
|
float
|
Line transparency. |
0.7
|
linestyles
|
str
|
Line style ( |
'solid'
|
labels
|
bool
|
Whether to add inline contour labels. |
False
|
label_fontsize
|
float or None
|
Font size for contour labels (when labels is |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
QuadContourSet
|
The contour set added to ax. |
Examples:
>>> fig, ax = plot_field_slice(data, "|B|")
>>> add_contours(ax, data, "P", levels=8, colors="white")
Source code in src/pypic/plotting/slices.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
plot_field_slice(data, field, *, plane=None, units=None, coord_units=None, theme=None, cmap=None, vmin=None, vmax=None, alpha=1.0, symmetric=None, log_scale=False, symlog=False, linthresh=None, title=None, step=None, time=None, ax=None, colorbar=True, colorbar_label=None, colorbar_variant=None, colorbar_ticks=None, extremes='semi', badge=False, save=None, figsize=None)
¶
Plot a 2D slice of a scalar field.
If data is 3D and no plane is given, defaults to a midplane
slice along the last axis (PlaneSelection(normal=axis_names[2])).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field
|
str
|
Field name — canonical, alias, or derived (e.g. |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
units
|
str | None
|
Display units for field values (e.g. |
None
|
coord_units
|
str, tuple[str, str], or None
|
Display units for coordinate axes. A single string applies to
both axes; a tuple |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | Colormap | None
|
Override automatic colormap selection. |
None
|
vmin
|
float | None
|
Color limits. |
None
|
vmax
|
float | None
|
Color limits. |
None
|
alpha
|
float
|
Mesh transparency (0 = invisible, 1 = opaque). Useful for overlaying semi-transparent scalar fields. |
1.0
|
symmetric
|
bool | None
|
Force symmetric color limits around zero. |
None
|
log_scale
|
bool
|
Use logarithmic color mapping ( |
False
|
symlog
|
bool
|
Use symmetric-log color mapping ( |
False
|
linthresh
|
float | None
|
Linear threshold for symlog. Values within |
None
|
title
|
str | None
|
Override auto-generated title. |
None
|
step
|
int | None
|
Timestep number for the title. |
None
|
time
|
float | None
|
Simulation time for the title. |
None
|
ax
|
Axes | None
|
Existing axes to draw on. |
None
|
colorbar
|
bool
|
Whether to add a colorbar. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
How to style values outside |
'semi'
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
colorbar_label
|
str or None
|
Override the colorbar label. |
None
|
colorbar_variant
|
str or None
|
Colorbar placement variant. |
None
|
colorbar_ticks
|
Sequence[float] or None
|
Explicit colorbar tick positions. |
None
|
badge
|
str or None
|
Corner badge text (run label, timestamp, ...). |
False
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/slices.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
plot_power_spectrum(k, power, *, label=None, compensated=None, reference_slopes=None, theme=None, xlabel=None, ylabel=None, title=None, ax=None, save=None, figsize=None, **kwargs)
¶
Plot a power spectrum on log-log axes.
Designed for output from power_spectrum_1d
or power_spectrum_2d.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
FloatArray
|
Wavenumber array. |
required |
power
|
FloatArray
|
Power spectral density. |
required |
label
|
str | None
|
Legend label for this spectrum. |
None
|
compensated
|
float | None
|
Multiply power by \(k^n\) before plotting (e.g. |
None
|
reference_slopes
|
list[float] | None
|
Draw dashed reference lines with these slopes on the log-log
plot (e.g. |
None
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
xlabel
|
str | None
|
X-axis label. |
None
|
ylabel
|
str | None
|
Y-axis label. |
None
|
title
|
str | None
|
Axes title. |
None
|
ax
|
Axes | None
|
Existing axes. |
None
|
save
|
str | None
|
Save figure to this path. |
None
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/spectral.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 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 | |
apply_grid(ax, theme, *, minor=False)
¶
Enable subtle grid lines styled for theme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Target axes. |
required |
theme
|
PlotTheme
|
Theme providing |
required |
minor
|
bool
|
If |
False
|
Source code in src/pypic/plotting/styles.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
apply_theme_to_figure(fig, theme)
¶
Set figure facecolors, text colors, and tick colors to match theme.
Useful when the figure was created outside use_theme(). Applies
background, text, tick, spine, and legend colors to all axes on the
figure.
Source code in src/pypic/plotting/styles.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
get_active_theme()
¶
Return the theme set by the innermost use_theme context, or None.
Source code in src/pypic/plotting/styles.py
301 302 303 | |
get_theme()
¶
Return the current default theme.
Loads light from the theme directory on first call if no
default has been set.
Examples:
>>> get_theme().name
'light'
Source code in src/pypic/plotting/styles.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
set_theme(theme)
¶
Set the default theme for all pypic plot functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
theme
|
ThemeArg
|
Theme name, path, or object. |
required |
Examples:
>>> set_theme("dark")
>>> get_theme().name
'dark'
>>> set_theme("light")
Source code in src/pypic/plotting/styles.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
style_legend(ax)
¶
Round the legend box corners if a legend is present.
Source code in src/pypic/plotting/styles.py
584 585 586 587 588 589 590 591 | |
use_theme(theme)
¶
Temporarily apply theme rcParams, restoring originals on exit.
Accepts a PlotTheme, a theme name string, a .toml
file path, or None (uses the current default).
Source code in src/pypic/plotting/styles.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
plot_quiver(data, field, *, plane=None, color=None, color_field=None, units=None, coord_units=None, alpha=1.0, theme=None, cmap=None, vmin=None, vmax=None, stride=1, scale=None, title=None, step=None, time=None, ax=None, colorbar=True, extremes='semi', legend=True, badge=False, save=None, figsize=None, **kwargs)
¶
Plot a quiver (arrow) field on a 2D slice.
By default, arrows are colored by in-plane magnitude through a
colormap. Pass color (e.g. "black") for uniform-color
arrows — useful as overlays on scalar field plots.
If data is 3D and no plane is given, defaults to a midplane slice along the last axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field
|
str
|
Vector field prefix — |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
color
|
str | None
|
Uniform arrow color (e.g. |
None
|
color_field
|
str | None
|
Scalar field for arrow color. |
None
|
units
|
str | None
|
Display units for the color field. |
None
|
coord_units
|
str, tuple[str, str], or None
|
Display units for coordinate axes. A single string applies to
both axes; a tuple |
None
|
alpha
|
float
|
Arrow transparency (0 = invisible, 1 = opaque). |
1.0
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | Colormap | None
|
Override automatic colormap selection. |
None
|
vmin
|
float or None
|
Color limits for the arrow colors. |
None
|
vmax
|
float or None
|
Color limits for the arrow colors. |
None
|
stride
|
int | tuple[int, int]
|
Subsample every N grid points. Scalar or |
1
|
scale
|
float | None
|
Quiver scale factor (passed to |
None
|
title
|
str | None
|
Override auto-generated title. |
None
|
step
|
int | None
|
Timestep number for the title. |
None
|
time
|
float | None
|
Simulation time for the title. |
None
|
ax
|
Axes | None
|
Existing axes to draw on. |
None
|
colorbar
|
bool
|
Whether to add a colorbar. Ignored when color is set. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
Colorbar out-of-range indicator style. |
'semi'
|
legend
|
bool or str
|
When color is set (uniform mode), add a vector legend overlay.
|
True
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
badge
|
str or None
|
Corner badge text (run label, timestamp, ...). |
False
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/vectors.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | |
plot_streamlines(data, field, *, plane=None, color=None, color_field=None, units=None, coord_units=None, alpha=1.0, theme=None, cmap=None, vmin=None, vmax=None, density=1.5, downsample=1, smooth=None, magnitude_min=None, magnitude_max=None, linewidth=None, arrowsize=1.0, arrowstyle='-|>', title=None, step=None, time=None, ax=None, colorbar=True, extremes='semi', legend=True, badge=False, save=None, figsize=None, **kwargs)
¶
Plot streamlines of a 2D vector field.
By default, lines are colored by in-plane magnitude through a
colormap. Pass color (e.g. "black") for uniform-color
streamlines — useful as overlays on scalar field plots.
If data is 3D and no plane is given, defaults to a midplane slice along the last axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FieldDataset
|
Input dataset (2D or 3D). |
required |
field
|
str
|
Vector field prefix — |
required |
plane
|
PlaneSelection | None
|
Plane selection for 3D data. |
None
|
color
|
str | None
|
Uniform line color (e.g. |
None
|
color_field
|
str | None
|
Scalar field for line color (e.g. |
None
|
units
|
str | None
|
Display units for the color field. |
None
|
coord_units
|
str, tuple[str, str], or None
|
Display units for coordinate axes. A single string applies to
both axes; a tuple |
None
|
alpha
|
float
|
Line and arrow transparency (0 = invisible, 1 = opaque). |
1.0
|
theme
|
PlotTheme | None
|
Plot theme. |
None
|
cmap
|
str | Colormap | None
|
Override automatic colormap selection. |
None
|
density
|
float
|
Streamline density (passed to |
1.5
|
downsample
|
int
|
Downsample the vector grid by this factor before tracing
streamlines. Values > 1 speed up |
1
|
smooth
|
float or None
|
Gaussian smoothing sigma in grid cells, applied to the vector
components before tracing. Suppresses grid-scale noise (useful
for PIC moment data). |
None
|
linewidth
|
float | tuple[float, float] | None
|
Fixed linewidth, or |
None
|
arrowsize
|
float
|
Arrow size scaling for streamplot. |
1.0
|
arrowstyle
|
str
|
Arrow style string (default |
'-|>'
|
title
|
str | None
|
Override auto-generated title. |
None
|
step
|
int | None
|
Timestep number for the title. |
None
|
time
|
float | None
|
Simulation time for the title. |
None
|
ax
|
Axes | None
|
Existing axes to draw on. |
None
|
colorbar
|
bool
|
Whether to add a colorbar. Ignored when color is set. |
True
|
extremes
|
"semi", "transparent", "darken", or None
|
Colorbar out-of-range indicator style. |
'semi'
|
legend
|
bool or str
|
When color is set (uniform mode), add a vector legend overlay.
|
True
|
figsize
|
tuple[float, float] | None
|
Figure size override. |
None
|
**kwargs
|
Any
|
Passed to |
{}
|
vmin
|
float or None
|
Lower color limit. |
None
|
vmax
|
float or None
|
Upper color limit. |
None
|
magnitude_min
|
float or None
|
Lower bound on vector magnitude; weaker vectors are
masked out. |
None
|
magnitude_max
|
float or None
|
Upper bound on vector magnitude; stronger vectors are
masked out. |
None
|
badge
|
str or None
|
Corner badge text (run label, timestamp, ...). |
False
|
save
|
str or Path or None
|
Path to write the figure to. When given, the figure is saved
and closed; when |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Source code in src/pypic/plotting/vectors.py
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 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |