Skip to content

array.plasma.plot

Plots of one labeled xarray.DataArray, as array.plasma.plot.<method>(...). Each method selects the dimensions it doesn’t draw by keyword (an integer is a position, t=-1 the last; a float the nearest value), draws, and returns a PlotResult (or an animation or a PyVista plotter).

Plots of one array, as array.plasma.plot.<kind>(...).

timeseriesmethod#

def timeseries(*others, logy: bool = True, fit=None, fit_amplitude: bool = False, title: str | None = None, ax=None, reference=None, backend: Backend | None = None)

Plot this time series, and any others given, in one axes.

Parameters

NameTypeDefaultDescription
*others()Further arrays with the single dimension t; they may come from other runs and need not share this array’s time grid.
logyboolTrueUse a logarithmic value axis. Default: True.
fit(float or None, float or None) or boolNoneTime window (t0, t1) of an exponential fit per series (None for an open end), or True for the whole series. Rates are in result.fit_results. Default: no fit.
fit_amplitudeboolFalseThe series is quadratic in an amplitude (e.g. an energy); fit the amplitude’s rate. Default: False.
titlestrNoneThe axes title. Default: the first series’ label.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
referencecallable, array, (t, values) pair or dictNoneExact or expected curves, drawn dashed: a function of t, an array, a (t, values) pair, or a mapping of labels to these.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes, the drawn lines, and in fit_results one FitResult (or None) per series.

Examples

>>> energy.plasma.plot.timeseries(
... logy=True, fit=(0.0, 2.0), fit_amplitude=True
... )
>>> energy.plasma.plot.timeseries(other_run_energy)

lineoutmethod#

def lineout(x: str | None = None, ax=None, title: str | None = None, reference=None, x_of=None, xlabel: str | None = None, rationals: int | None = None, nfp: int | None = None, backend: Backend | None = None, **selection)

Plot a one-dimensional profile after selecting every other dimension.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension to keep. Default: the only one left after selection.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe axes title. Default: the array’s label.
referencecallable, array, (x, y) pair or dictNoneExact or expected profiles, drawn dashed: a function of the plotted x (or of x and t, taking the profile’s time), a 1-D xarray.DataArray (drawn over its own coordinate), an (x, y) pair, or a dict of labels to these.
x_ofcallableNoneMaps the coordinate to the plotted axis, e.g. lambda eta1: L * eta1.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label.
rationalsintNoneMark where a rotational transform (or safety factor) profile takes its rationals lowest-order rational values n/m: a dotted line at each value, labeled, and a point at each crossing (see plasma_plots.analysis.rational_surfaces()). Default: none.
nfpintNoneWith rationals: the numerators n are multiples of it. Default: the profile’s nfp attribute, else 1.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The other dimensions: an integer is a position (t=-1 the last), a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn lines.

Examples

>>> phi.plasma.plot.lineout(x="eta1", t=-1, eta2=0.5, eta3=0)
>>> T.plasma.plot.lineout(
... x="eta1", t=-1, reference=exact, x_of=lambda eta1: L * eta1
... )
>>> # GVEC's ι(ρ) and its rational surfaces
>>> ev.iota.plasma.plot.lineout(rationals=4)

line_animationmethod#

def line_animation(x: str | None = None, sweep: str = 't', reference=None, x_of=None, xlabel: str | None = None, ylim=None, step: int = 1, max_frames: int | None = None, interval: int = 100, title: str | None = None, alongside=None, alongside_logy: bool = False, backend: Backend | None = None, **selection)

Animate a one-dimensional profile over sweep.

Optionally with the exact profile of each frame (reference=lambda x, t: ...). Keep a reference to the returned animation, or it stops.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis. Default: the one besides sweep.
sweepstr't'The dimension to animate over. Default: "t".
referencecallable, (x, y) pair or dictNoneThe exact profile of each frame, drawn dashed in black: a function of the plotted x and of the sweep value (lambda x, t: ...; a function of x alone is fixed), an (x, y) pair, a 1-D xarray.DataArray (drawn over its own coordinate), or a dict of labels to these.
x_ofcallableNoneMaps the x coordinate to the plotted axis, e.g. lambda eta1: L * eta1.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label, or "x" with x_of.
ylim(float, float)NoneThe fixed value axis limits. Default: the range of the data and references, padded by 5 %.
stepint1Use every step-th value of the sweep. Default: 1.
max_framesintNoneKeep at most this many frames, evenly spaced over those step leaves (the first and last included), e.g. to keep a Plotly animation small. Default: all.
intervalint100The delay between frames, in milliseconds. Default: 100.
titlestrNoneThe title, followed in each frame by the sweep value. Default: the array’s label.
alongsidesequenceNoneOne panel below the profile per item, in sync with it: an array over sweep and one other dimension (another profile, animated, e.g. the density next to the velocity), or an array over sweep alone, or a list of those (time series such as energies, drawn whole with a marker at each frame’s value of the sweep, nearest where the times differ). Default: none.
alongside_logyboolFalseLogarithmic value axes for the time-series panels. Default: False.
backend('matplotlib', 'plotly')"matplotlib"Draw with Matplotlib, or as an interactive Plotly figure with a slider (in result.fig; needs plotly, see plasma_plots.plotly_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x and sweep: an integer is a position (eta2=0), a float the nearest coordinate value.

Returns

matplotlib.animation.FuncAnimation or PlotResult
The animation, one frame per step along sweep; with backend="plotly" a result whose Plotly figure has a slider and Play/Pause buttons.

Examples

>>> T.plasma.plot.line_animation(reference={"exact": exact}, step=2)
>>> u.plasma.plot.line_animation(
... x="eta1",
... alongside=[n, [en_U, en_B]],
... alongside_logy=True,
... eta2=0,
... eta3=0,
... )

against_theorymethod#

def against_theory(theory=None, *, show_error: bool = True, xlabel=None, ylabel=None, title=None, logx: bool = False, logy: bool = False, backend: Backend | None = None)

Plot these measured values as points against a theory function.

The array is 1-D, over a parameter (e.g. the wavenumber); the relative error is shown too.

Parameters

NameTypeDefaultDescription
theorycallable, (x, y) pair or dictNoneA function of the parameter, an (x, y) pair, or a dict of labels to these, drawn as lines over the measured range. Complex values (e.g. from plasma_plots.theory) are compared by their real part; for growth or damping rates pass lambda k: f(k).imag.
show_errorboolTrueAdd a second panel with (measured - theory) / theory against the first theory, for every measured series. A theory given as points is interpolated linearly between them (NaN outside them). Default: True.
xlabelstrNoneThe horizontal axis label. Default: the coordinate label of the first measured array.
ylabelstrNoneThe value axis label. Default: the value label of the first measured array.
titlestrNoneThe title. Default: "Measured against theory".
logxboolFalseUse a logarithmic parameter axis. Default: False.
logyboolFalseUse a logarithmic value axis. Default: False.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes (with show_error, the upper one) and the drawn artists.

Examples

>>> traced = spectrum.plasma.analysis.trace_branch(
... bohm_gross, k_range=(1.5, 5.5)
... )
>>> traced.omega.plasma.plot.against_theory(bohm_gross)

convergencemethod#

def convergence(*others, order: float | None = None, xlabel: str | None = None, title: str = 'Convergence', ax=None, backend: Backend | None = None)

Plot these errors against their resolution (or step size) on log-log axes, with the order.

The array is 1-D over the resolution, e.g. an error norm per number of cells; each series gets its fitted convergence order (or, with order, a reference slope).

Parameters

NameTypeDefaultDescription
*others()Further 1-D error arrays, e.g. of other methods or norms, drawn in the same axes.
orderfloatNoneWith None (default), fits and draws the observed order via plasma_plots.analysis.convergence_order(). Pass an explicit order (e.g. 2 for second-order) to draw a reference slope through the first point instead of fitting one.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label.
titlestr'Convergence'The axes title. Default: "Convergence".
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and, per series, the error line and its fitted or reference line.

Raises

ValueError
If an array is not one-dimensional.

Examples

>>> errors = xr.DataArray(
... l2_errors, dims="n", coords={"n": [16, 32, 64, 128]}, name="L2 error"
... )
>>> errors.plasma.plot.convergence(max_errors, backend="plotly")

vectormethod#

def vector(x: str, y: str, components: tuple[int, int] = (0, 1), stride: int = 1, coordinates: Coordinates = 'logical', ax=None, backend: Backend | None = None, **selection)

Plot two vector components after selecting time and remaining dimensions.

Parameters

NameTypeDefaultDescription
xstrrequiredThe dimension along the horizontal axis.
ystrrequiredThe dimension along the vertical axis.
components(int, int)(0, 1)The positions along component_dim of the two components drawn. Default: (0, 1).
strideint1Draw every stride-th arrow along x and y. Default: 1.
coordinates('logical', 'physical')"logical"Place the arrows at the logical coordinates, or at the attached physical X, Y, Z (then x and y must be two of eta1, eta2, eta3, and the axes have equal scales). Default: "logical".
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x, y and the component dimension, e.g. t=-1, eta3=0: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the quiver.

Examples

>>> E.plasma.plot.vector(x="eta1", y="eta2", t=-1, eta3=0)

volume_slicesmethod#

def volume_slices(indices: dict[str, int] | None = None, cmap=None, backend: Backend | None = None, **selection)

Render three orthogonal slices of a selected scalar volume.

Parameters

NameTypeDefaultDescription
indicesdict of str to intNoneThe index at which each dimension is held fixed, e.g. {"eta3": 0}. Default: the middle index of every dimension.
cmapstr or matplotlib.colors.ColormapNoneThe colormap. Default: Matplotlib’s default.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but the three of the volume, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the three axes and the drawn meshes.

Examples

>>> density.plasma.plot.volume_slices(t=-1)

volumemethod#

def volume(name: str | None = None, cmap='viridis', opacity='linear', **selection)

Create a PyVista volume plotter for a selected scalar field.

Parameters

NameTypeDefaultDescription
namestrNoneThe name of the scalars in the PyVista grid. Default: the array’s label, else "value".
cmapstr'viridis'The colormap. Default: "viridis".
opacitystr or sequence of float'linear'PyVista’s opacity transfer function. Default: "linear".
**selection{}Every dimension but eta1, eta2, eta3, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

pyvista.Plotter
The plotter, not yet shown; call plotter.show().

Examples

>>> density.plasma.plot.volume(cmap="viridis", opacity="linear", t=-1).show()

isosurfacemethod#

def isosurface(values=5, cmap='viridis', opacity: float = 1.0, clim=None, show_domain: bool = True, title: str | None = None, symmetric: bool = False, robust: bool = False, plotter=None, **selection)

Draw PyVista contour surfaces of this scalar field in physical space.

For a 2-D field, contour lines over the colored plane instead.

Parameters

NameTypeDefaultDescription
valuesint or list of float5The number of evenly spaced levels strictly between the color limits, or explicit levels. Default: 5.
cmapstr or matplotlib colormap'viridis'The colormap. Default: "viridis".
opacityfloat1.0Opacity of the surfaces (of the plane for a 2-D field). Default: 1.
clim(float, float)NoneColor limits; default from the field’s values, see symmetric and robust.
show_domainboolTrueDraw the domain’s outer surface translucently for context (3-D fields only). Default: True.
titlestrNoneText in the scene’s corner. Default: the field’s label; "" for none.
symmetricboolFalseColor limits symmetric about zero. Default: False.
robustboolFalseColor limits from percentiles instead of the extremes, so outliers don’t wash out the colors. Default: False.
plotterpyvista.PlotterNoneDraw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter.
**selection{}Every dimension but eta1, eta2, eta3, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

pyvista.Plotter
The plotter with the surfaces, not yet shown.

Examples

>>> phi.plasma.plot.isosurface(values=[-0.5, 0.5], cmap="RdBu_r", t=0).show()

slices_3dmethod#

def slices_3d(cuts: dict | None = None, cmap='viridis', clim=None, show_domain: bool = True, title: str | None = None, symmetric: bool = False, robust: bool = False, plotter=None, **selection)

Draw PyVista surfaces of constant logical coordinate in physical space.

E.g. cuts={"eta3": [0, 0.25]} for poloidal cross-sections, cuts={"eta1": 0.8} for one flux surface. A 2-D field is shown as its whole plane by default.

Parameters

NameTypeDefaultDescription
cutsdictNone{dim: position or list of positions} along eta1, eta2, eta3: a float is the nearest logical coordinate, an integer a grid index (-1 the last). Default: the middle of every dimension, or the whole plane of a 2-D field.
cmapstr or matplotlib colormap'viridis'The colormap. Default: "viridis".
clim(float, float)NoneColor limits, shared by every cut; default from the whole field’s values, see symmetric and robust.
show_domainboolTrueDraw the domain’s outer surface translucently for context. Not drawn when the whole plane of a 2-D field is shown. Default: True.
titlestrNoneText in the scene’s corner. Default: the field’s label; "" for none.
symmetricboolFalseColor limits symmetric about zero. Default: False.
robustboolFalseColor limits from percentiles instead of the extremes, so outliers don’t wash out the colors. Default: False.
plotterpyvista.PlotterNoneDraw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter.
**selection{}Every dimension but eta1, eta2, eta3, e.g. t=0: an integer is a position, a float the nearest coordinate value.

Returns

pyvista.Plotter
The plotter with the cuts, not yet shown.

Examples

>>> phi.plasma.plot.slices_3d(
... cuts={"eta3": [0, 0.25, 0.5, 0.75]}, cmap="RdBu_r", t=0
... ).show()

glyphsmethod#

def glyphs(components: Literal['cartesian', 'contravariant'] = 'cartesian', stride: int = 2, scale: float | None = None, cmap='viridis', show_domain: bool = True, title: str | None = None, plotter=None, **selection)

Draw PyVista arrows of this (component, eta1, eta2, eta3) vector field.

The arrows are colored by magnitude.

Parameters

NameTypeDefaultDescription
components('cartesian', 'contravariant')"cartesian"How to read the components: Cartesian x/y/z, or contravariant logical components, pushed forward. Default: "cartesian".
strideint2Draw an arrow at every stride-th point in every direction. Default: 2.
scalefloatNoneArrow length of the largest vector, in physical units. Default: a tenth of the domain size.
cmapstr or matplotlib colormap'viridis'The colormap of the magnitude. Default: "viridis".
show_domainboolTrueDraw the domain’s outer surface translucently for context. Default: True.
titlestrNoneText in the scene’s corner. Default: the field’s label; "" for none.
plotterpyvista.PlotterNoneDraw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter.
**selection{}Every dimension but component, eta1, eta2, eta3, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

pyvista.Plotter
The plotter with the arrows, not yet shown.

Examples

>>> B.plasma.plot.glyphs(stride=3, t=-1).show()

streamlinesmethod#

def streamlines(components: Literal['cartesian', 'contravariant'] = 'cartesian', n_points: int = 100, source_radius: float | None = None, source_center=None, max_length: float | None = None, tube_radius: float | None = None, cmap='viridis', show_domain: bool = True, title: str | None = None, plotter=None, **selection)

Draw PyVista field lines of this vector field, e.g. magnetic field lines.

Parameters

NameTypeDefaultDescription
components('cartesian', 'contravariant')"cartesian"How to read the components: Cartesian x/y/z, or contravariant logical components, pushed forward by [push_forward()][push_forward]. Default: "cartesian".
n_pointsint100The number of seed points (at most the number of grid points when seeding on the grid). Default: 100.
source_radiusfloatNoneSeed in a sphere of this radius instead of at grid points. Default (when source_center is given): a quarter of the domain size.
source_center(float, float, float)NoneSeed in a sphere around this physical point instead of at grid points. Default (when source_radius is given): the bounding-box center.
max_lengthfloatNoneMaximum length of each line. Default: four times the domain size.
tube_radiusfloatNoneDraw the lines as tubes of this radius. Default: plain lines.
cmapstr or matplotlib colormap'viridis'The colormap of the magnitude. Default: "viridis".
show_domainboolTrueDraw the domain’s outer surface translucently for context. Default: True.
titlestrNoneText in the scene’s corner. Default: "<label> field lines"; "" for none.
plotterpyvista.PlotterNoneDraw into this scene instead of a new one, to combine several views. The camera is only aimed at the field when this function creates the plotter.
**selection{}Every dimension but component, eta1, eta2, eta3, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

pyvista.Plotter
The plotter with the field lines, not yet shown.

Examples

>>> B.plasma.plot.streamlines(
... n_points=60, source_center=(3.5, 0, 0), t=-1
... ).show()

moviemethod#

def movie(path, *, kind: Literal['isosurface', 'slices', 'glyphs', 'streamlines'] = 'slices', step: int = 1, framerate: int = 10, clim=None, **options)

Render one PyVista 3-D view per time step into a GIF or video.

Every dimension but t and the spatial (and component) dimensions must already be selected.

Parameters

NameTypeDefaultDescription
pathstr or pathlib.PathrequiredThe output file: a GIF for .gif, a video (e.g. .mp4) for any other suffix.
kind('isosurface', 'slices', 'glyphs', 'streamlines')"isosurface"The view of each frame. Default: "slices".
stepint1Use every step-th position of sweep. Default: 1.
framerateint10Frames per second. Default: 10.
clim(float, float)NoneColor limits of the scalar views ("isosurface", "slices"). Default: from the whole sweep, with the symmetric and robust options.
**options{}Options of the chosen view, e.g. cuts= for kind="slices" (see slices_3d(), isosurface(), glyphs(), streamlines()).

Returns

str
The path of the written file.

Examples

>>> phi.plasma.plot.movie(
... "mode.gif",
... kind="slices",
... cuts={"eta3": [0, 0.25, 0.5, 0.75]},
... cmap="RdBu_r",
... )

comparemethod#

def compare(other: xr.DataArray, *, mode: Literal['difference', 'ratio'] = 'difference', ax=None, backend: Backend | None = None)

Plot a one-dimensional aligned difference or ratio against another array.

Parameters

NameTypeDefaultDescription
otherxarray.DataArrayrequiredThe array to compare with, e.g. a reference run; aligned with this one first.
mode('difference', 'ratio')"difference"first - second, or first / second (NaN where second is zero). Default: "difference".
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn line.

Examples

>>> field.plasma.plot.compare(reference_field, mode="ratio")

overlay_orbitsmethod#

def overlay_orbits(orbits: xr.Dataset, *, x: str, y: str, max_markers: int = 200, ax=None, cmap=None, backend: Backend | None = None, **selection)

Plot this field’s slice with marker orbit paths from orbits overlaid.

A Poincare-style diagnostic for checking particle confinement or orbit topology against a background field.

Parameters

NameTypeDefaultDescription
orbitsxarray.DatasetrequiredAn orbits product with position variables named after view.x and view.y (e.g. its logical coordinates, to overlay directly on a logical-coordinates slice).
xstrrequiredThe horizontal dimension of the slice. orbits must have a position variable of the same name (e.g. logical eta1, to overlay directly on a logical-coordinates slice of this field).
ystrrequiredThe vertical dimension of the slice; orbits needs a variable of this name too.
max_markersint200Draw only the first max_markers markers. Default: 200.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
cmapstr or matplotlib.colors.ColormapNoneThe colormap of the field. Default: "viridis".
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every other dimension of this field, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the slice’s mesh and one line per orbit.

Examples

>>> phi.plasma.plot.overlay_orbits(orbits, x="eta1", y="eta2", t=-1, eta3=0)

dispersionmethod#

def dispersion(dim: str | None = None, detrend: bool = True, branches: dict | None = None, log: bool = True, dynamic_range: float = 6.0, kmin: float | None = None, kmax: float | None = None, omega_max: float | None = None, vmin: float | None = None, vmax: float | None = None, cmap=None, ax=None, title: str | None = None, frequencies: dict | None = None, points: dict | None = None, fits=(), backend: Backend | None = None)

Plot the space-time power spectrum of this (t, dim) field as a dispersion relation.

branches optionally overlays named theoretical curves (a mapping of label to a callable omega(k), or an explicit (k, omega) pair), to compare against, e.g. {"Bohm-Gross": lambda k: np.sqrt(1 + 3 * k**2)}. frequencies draws labeled horizontal lines (cutoffs), points measured points ((k, omega) pairs or plasma_plots.spectral.trace_branch() results).

Parameters

NameTypeDefaultDescription
dimstrNoneThe spatial dimension to transform. Default: the one besides t (see plasma_plots.analysis.power_spectrum()).
detrendboolTrueRemove the time-mean at each point of dim first, which otherwise dominates the spectrum as a spurious zero-frequency line. Default: True.
branchesdict or callableNoneTheoretical curves to compare against, drawn dashed: a dict of labels to a callable omega(k) or an explicit (k, omega) pair of arrays; or one callable that returns a dict of branch names to frequencies, such as the dispersion relations of plasma_plots.theory or Struphy’s struphy.dispersion_relations objects (a callable in the dict may return such a dict too). Complex frequencies are drawn by their real part.
logboolTrueColor by log10 of the power. Default: True.
dynamic_rangefloat6.0With log, the number of decades below the peak that the default color limits cover. Default: 6.0.
kminfloatNoneShow only k >= kmin, e.g. 0 for the positive quadrant. Default: all k.
kmaxfloatNoneShow only |k| <= kmax. Default: all k.
omega_maxfloatNoneShow only ω <= omega_max. Default: all non-negative ω.
vminfloatNoneThe lower color limit (in log10 of the power with log). Default: the peak minus dynamic_range with log, else the minimum.
vmaxfloatNoneThe upper color limit (in log10 of the power with log). Default: the peak.
cmapstr or matplotlib.colors.ColormapNoneThe colormap. Default: Matplotlib’s default.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe axes title. Default: "Dispersion relation of <label>".
frequenciesdict of str to floatNoneLabeled horizontal lines, e.g. cutoffs or resonances.
pointsdictNoneMeasured points to mark: a dict of labels to a (k, omega) pair or a trace_branch() result (an xarray.Dataset with k and omega).
fitssequence of BranchFit()Fitted straight branches from fit_dispersion_branches(), drawn dotted as omega = velocity * k over the shown k >= 0. Default: none.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists.

Examples

>>> E.plasma.plot.dispersion(
... dim="eta1", branches={"Bohm-Gross": lambda k: np.sqrt(1 + 3 * k**2)}
... )
>>> # or pass the spectrum itself
>>> spectrum = E.plasma.analysis.dispersion(dim="eta1")
>>> fits = spectrum.plasma.analysis.fit_branches(n_branches=1)
>>> spectrum.plasma.plot.dispersion(
... kmin=0, fits=fits, dynamic_range=15, backend="plotly"
... )

power_spectrummethod#

def power_spectrum(dims=None, detrend: bool = True, window: str | None = None, peaks: int | None = None, band=None, frequencies: dict | None = None, logy: bool = True, omega_max: float | None = None, ax=None, title: str | None = None, backend: Backend | None = None, **selection)

Plot the power per frequency bin, averaged over dims.

dims defaults to all but component; optional peak labels, a shaded filter band and reference frequencies.

Parameters

NameTypeDefaultDescription
dimsstr or sequence of strNoneDimensions to average the power over. At most one other dimension may remain, which gives one line per coordinate value. Default: every dimension but omega and component.
detrendboolTrueSubtract the signal’s mean before transforming. Default: True.
window(None, 'hann')NoneWindow applied before transforming a signal. Default: None.
peaksintNoneMark and label this many of the strongest peaks of a single line, with sub-bin frequencies (see spectral_peaks()). Default: none.
band(TimeFilterResult, xarray.Dataset or (float, float))NoneA frequency band to shade: a filter_time() result or its spectrum (with one band selected), or an (omega_lo, omega_hi) pair.
frequenciesdictNoneNamed reference frequencies drawn as vertical dotted lines, e.g. {"gap": 0.8} for a continuum-gap estimate.
logyboolTrueLogarithmic power axis. Default: True.
omega_maxfloatNoneThe highest frequency shown. Default: all.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe axes title. Default: the power’s label.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Dimensions other than t to select first (e.g. a probe point eta1=0.4): an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn artists; data holds the averaged "power" and the found "peaks".

Examples

>>> band = phi.plasma.analysis.filter_time(dims=("eta1", "eta2", "eta3"))
>>> phi.plasma.plot.power_spectrum(
... peaks=2, band=band, frequencies={"TAE gap": omega_tae}
... )

filteredmethod#

def filtered(result, *, ax=None, backend: Backend | None = None, **selection)

Plot a probe of this signal against a filtered reconstruction.

result is a ArrayAnalysis.filter_time() result or a filtered array; the probe is selected by keyword.

Parameters

NameTypeDefaultDescription
resultTimeFilterResult or xarray.DataArrayrequiredA TimeFilterResult or a filtered array (e.g. from band_filter()) on the grid of data.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but t, selected by keyword: an integer is a position (-1 the last), a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, and the raw and the filtered line.

Examples

>>> band = phi.plasma.analysis.filter_time(dims=("eta1", "eta2", "eta3"))
>>> phi.plasma.plot.filtered(band, eta1=0.4, eta2=0.0, eta3=0.0)

spectrogrammethod#

def spectrogram(length, step=None, detrend: bool = True, window: str | None = 'hann', log: bool = True, dynamic_range: float = 4.0, omega_max: float | None = None, frequencies: dict | None = None, ax=None, backend: Backend | None = None, **selection)

Plot short-time power spectra over (t, omega).

Any dimensions that remain after selection are averaged.

Parameters

NameTypeDefaultDescription
lengthint or floatrequiredThe window length: a number of samples (integer) or a time span (float).
stepint or floatNoneThe shift between windows, in the same forms. Default: a quarter of length.
detrendboolTrueSubtract each window’s mean first. Default: True.
window('hann', None)"hann"The taper of each window. Default: "hann".
logboolTrueColor by log10(power). Default: True.
dynamic_rangefloat4.0With log, the number of decades the colors span below the maximum. Default: 4.0.
omega_maxfloatNoneThe highest frequency shown. Default: all.
frequenciesdictNoneNamed reference frequencies drawn as horizontal dotted lines.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Dimensions other than t to select first: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn artists; data["spectrogram"] is the power.

Examples

>>> signal.plasma.plot.spectrogram(length=200.0, step=10.0, omega_max=0.45)

mode_amplitudesmethod#

def mode_amplitudes(dims=None, names=('m', 'n'), top: int = 6, fit=None, reduce: str = 'max', scale=None, relative: bool = False, logy: bool = True, ax=None, backend: Backend | None = None, **selection)

Plot the amplitude of the strongest (m, n) modes of this field over time.

Each mode is reduced over the remaining dimensions (e.g. radius) by reduce, with optional growth fits (fit=(t0, t1) or True).

Parameters

NameTypeDefaultDescription
dimssequence of strNoneThe periodic dimensions to decompose. Default: the two logical angles, ("eta2", "eta3") or GVEC’s (see plasma_plots.spectral.mode_spectrum()).
namessequence of str('m', 'n')The names of the mode numbers along dims. Default: ("m", "n").
topint6The number of modes drawn, those with the largest peak amplitude. Default: 6.
fit(float, float) or boolNoneFit an exponential growth rate γ to each mode: a time window (t0, t1), or True for the whole record. Default: no fit.
reduce('max', 'mean')"max"How each mode is reduced over the remaining dimensions. Default: "max".
scaleint or sequence of intNoneMultiplies the mode numbers, e.g. (1, 6) for full-torus n of a sixth of a torus. Default: 1, or nfp along GVEC’s toroidal angle (see plasma_plots.spectral.mode_spectrum()).
relativeboolFalseShow each mode relative to the mean (the zero mode). Default: False.
logyboolTrueLogarithmic amplitude axis. Default: True.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Dimensions other than t to select first: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the drawn lines, the fits in fit_results and the plotted data["amplitudes"].

Examples

>>> phi.plasma.plot.mode_amplitudes(top=2, fit=(100, 500))

mode_mapmethod#

def mode_map(dims=None, m_range=None, n_range=None, reduce: str = 'max', scale=None, log: bool = True, ax=None, backend: Backend | None = None, **selection)

Plot |amplitude| over the (m, n) plane at one time.

The time is selected by keyword (e.g. t=-1); the amplitude is reduced over the remaining dimensions by reduce.

Parameters

NameTypeDefaultDescription
dimssequence of strNoneThe two periodic dimensions to decompose. Default: the two logical angles, ("eta2", "eta3") or GVEC’s (see plasma_plots.spectral.mode_spectrum()).
m_range(int, int)NoneThe range of m shown, both ends included. Default: all.
n_range(int, int)NoneThe range of n shown, both ends included. Default: all.
reduce('max', 'mean')"max"How the amplitude is reduced over the remaining dimensions. Default: "max".
scaleint or sequence of intNoneMultiplies the mode numbers, e.g. (1, 6) for full-torus n of a sixth of a torus. Default: 1, or nfp along GVEC’s toroidal angle (see plasma_plots.spectral.mode_spectrum()).
logboolTrueColor by log10(|amplitude|), clipped at 4 decades below the maximum. Default: True.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The time and any other dimensions to select first, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the mesh and the plotted data["amplitude"].

Examples

>>> phi.plasma.plot.mode_map(t=-1, m_range=(0, 16))

radial_powermethod#

def radial_power(x: str | None = None, x_of=None, xlabel: str | None = None, continuum=None, detrend: bool = True, window: str | None = None, log: bool = True, dynamic_range: float = 3.0, omega_max: float | None = None, ax=None, backend: Backend | None = None, **selection)

Plot the time-power over (omega, x), averaged over the other dimensions.

The other dimensions are e.g. the angles; optional continuous spectra are drawn on top.

Parameters

NameTypeDefaultDescription
xstrNoneThe spatial dimension. Default: the radial logical one (eta1, or GVEC’s rho).
x_ofcallableNoneMaps the x coordinate to the plotted axis, e.g. lambda eta1: 0.1 + 0.9 * eta1 for the minor radius of a hollow torus. The axis is then labeled r.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label, or r with x_of.
continuumtuple or xarray.DataArrayNoneContinuous spectra overlaid as curves: a (spectrum, modes) pair as for plot_continuous_spectrum(), evaluated on the plotted axis, or a (mode, branch, x) array from prepare_continuous_spectrum().
detrendboolTrueSubtract the temporal mean first. Default: True.
window(None, 'hann')NoneThe taper of the time FFT. Default: None (boxcar).
logboolTrueColor by log10(power), clipped at dynamic_range decades below the maximum. Default: True.
dynamic_rangefloat3.0With log, the number of decades shown. Default: 3.0.
omega_maxfloatNoneThe highest frequency shown. Default: all.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Dimensions to select first: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the drawn artists and the plotted data["power"].

Examples

>>> phi.plasma.plot.radial_power(
... x_of=lambda eta1: 0.1 + 0.9 * eta1, omega_max=0.5
... )

mode_profilesmethod#

def mode_profiles(omega: float | None = None, *, x: str | None = None, dims=None, x_of=None, xlabel: str | None = None, top: int = 4, phase: bool = True, scale=None, backend: Backend | None = None, **selection)

Plot the radial profile of each (m, n) harmonic of this field.

Parameters

NameTypeDefaultDescription
omegafloatNoneA frequency: the eigenfunction at that frequency (amplitude and phase), mode_spectrum(mode_structure(field, omega)). Default: the harmonics’ amplitudes at one time, which is then selected by keyword (e.g. t=-1).
xstrNoneThe radial dimension. Default: the radial logical one (eta1, or GVEC’s rho).
dimssequence of strNoneThe periodic dimensions to decompose. Default: the two logical angles, ("eta2", "eta3") or GVEC’s (see plasma_plots.spectral.mode_spectrum()).
x_ofcallableNoneMaps the x coordinate to the plotted axis, e.g. lambda eta1: 0.1 + 0.9 * eta1. The axis is then labeled r.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label, or r with x_of.
topint4The number of strongest harmonics drawn; (m, n) and (-m, -n) count as one (the stronger is drawn, labeled by the half whose first nonzero number is positive). Default: 4.
phaseboolTrueAdd the phase panel (only for complex structure). Default: True.
scaleint or sequence of intNoneMultiplies the mode numbers, e.g. (1, 6) for full-torus n of a sixth of a torus. Default: 1, or nfp along GVEC’s toroidal angle (see plasma_plots.spectral.mode_spectrum()).
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Dimensions to select first (without omega, the time): an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the drawn lines and the plotted data["profiles"].

Raises

ValueError
Without omega, if t is not selected.

Examples

>>> phi.plasma.plot.mode_profiles(
... omega, x_of=lambda eta1: 0.1 + 0.9 * eta1, top=2
... )
>>> phi.plasma.plot.mode_profiles(t=-1, scale=(1, 6))

profilesmethod#

def profiles(x: str | None = None, over: str = 't', at=None, x_of=None, xlabel: str | None = None, ax=None, title: str | None = None, reference=None, backend: Backend | None = None, **selection)

Plot profiles along x at several values of over in one axes.

By default four times. x_of maps x to the plotted axis (e.g. the minor radius); reference overlays the exact profiles (lambda x, t: ...).

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis. Default: the radial logical one (eta1, or GVEC’s rho).
overstr't'The dimension to draw one profile per value of. Default: "t".
atint, float or sequence of theseNoneThe values of over: integers are positions, floats nearest values. Default: four evenly spaced positions.
x_ofcallableNoneMaps the x coordinate to the plotted axis, e.g. lambda eta1: 0.1 + 0.9 * eta1 for the minor radius of a hollow torus.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s label, or "r" with x_of.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe axes title. Default: the array’s label.
referencecallable, array, (x, y) pair or dictNoneExact or expected profiles, drawn in each profile’s color in dashed styles: a function of the plotted x (or of x and the value of over), a 1-D xarray.DataArray (drawn over its own coordinate), an (x, y) pair, or a dict of labels to these.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every other dimension, e.g. eta2=0.125, eta3=0: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn lines.

Examples

>>> T.plasma.plot.profiles(
... x="eta1", at=[0, 10, 20, 40], reference={"exact": exact}
... )

cross_spectrummethod#

def cross_spectrum(other: xr.DataArray, *, dims=None, detrend: bool = True, window=None, omega_max=None, backend: Backend | None = None)

Plot the magnitude, coherence and phase of other relative to this signal.

The coherence is shown only with dims.

Parameters

NameTypeDefaultDescription
otherxarray.DataArrayrequiredThe second signal, on the same time grid; its phase is relative to this one.
dimsstr or sequence of strNoneDimensions to sum the cross-spectrum over, as an ensemble. Default: none (no coherence).
detrendboolTrueSubtract each signal’s temporal mean first. Default: True.
window(None, 'hann')NoneWindow applied to both signals before transforming. Default: None.
omega_maxfloatNoneThe largest angular frequency shown. Default: all.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the axes and the drawn artists; data holds "peak_omega" and "peak_phase_deg".

Examples

>>> u.plasma.plot.cross_spectrum(b, dims="eta3", omega_max=1.5)

pencil_fitmethod#

def pencil_fit(n_modes: int = 1, pencil: int | None = None, detrend: bool = False, backend: Backend | None = None, **selection)

Plot a matrix-pencil fit of this (t,) series.

The samples against the fit, and the modes in the complex-frequency plane.

Parameters

NameTypeDefaultDescription
n_modesint1The number of modes to fit and return: real oscillations for a real signal, complex exponentials for a complex one. The fit needs well over 2 * n_modes samples. Default: 1.
pencilintNoneThe pencil parameter (Hankel matrix width minus one), which trades noise robustness against resolution. Default: N // 2.
detrendboolFalseSubtract the mean first. Default: False.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but t, e.g. a probe point: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn artists; data holds the "fit" and the reconstructed "model".

Examples

>>> probe.plasma.plot.pencil_fit(n_modes=1)

viewmethod#

def view(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, **selection) -> 'SliceView'

Configure a reusable slice view without rendering a figure.

Use xarray’s .sel()/.isel() for general selection, or pass remaining dimensions here. The options apply to every presentation of the view: slice(), panels(), viewer(), animation() and frames() take the same ones.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

SliceView
The configured view; it creates no figure and does not copy the array.

Examples

>>> view = f.plasma.plot.view(x="eta1", y="v1", cmap="RdBu_r")
>>> view.slice(t=-1)
>>> view.panels(nrows=2, ncols=3)
>>> view.save_frames("frames")

slicemethod#

def slice(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, ax=None, backend: Backend | None = None, **selection)

Render one 2-D slice.

The same as plot.view(...).slice(ax=ax); see view() for the shared options.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

PlotResult
The figure, the axes and the drawn mesh.

Examples

>>> phi.plasma.plot.slice(x="eta1", y="eta2", t=-1)
>>> n.plasma.plot.slice(
... coords="physical", plane="XY", t=-1, eta3=0, levels=[0.2]
... )

panelsmethod#

def panels(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, nrows: int = 3, ncols: int = 4, backend: Backend | None = None, **selection)

Render evenly spaced snapshots along the sweep.

The same as plot.view(...).panels(nrows=nrows, ncols=ncols); see view() for the shared options.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
nrowsint3The number of panel rows. Default: 3.
ncolsint4The number of panel columns. Default: 4.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

PlotResult
The figure, the array of axes and the drawn meshes.

Examples

>>> phi.plasma.plot.panels(x="eta1", y="eta2", nrows=2, ncols=3, eta3=0)

viewermethod#

def viewer(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, backend: Backend | None = None, **selection)

Create an interactive slider view; keep a reference to the returned viewer.

The same as plot.view(...).viewer(); see view() for the shared options.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
backend('matplotlib', 'plotly')"matplotlib"Draw with Matplotlib, or as an interactive Plotly figure with a slider (in result.fig; needs plotly, see plasma_plots.plotly_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

plasma_plots.plotting.InteractiveSliceViewer or PlotResult
The viewer, with sliders for the unselected dimensions; with backend="plotly" a result whose Plotly figure has one slider (one unselected dimension at most).

Examples

>>> viewer = phi.plasma.plot.viewer(x="eta1", y="eta2")

animationmethod#

def animation(x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, interval: int = 100, step: int = 1, max_frames: int | None = None, alongside=None, backend: Backend | None = None, **selection)

Animate the sweep; keep a reference to the returned Matplotlib animation.

The same as plot.view(...).animation(...); see view() for the shared options.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
intervalint100The delay between frames, in milliseconds. Default: 100.
stepint1Show every step-th element of the sweep. Default: 1.
max_framesintNoneKeep at most this many frames, evenly spaced over those step leaves (the first and last included), e.g. to keep a Plotly animation small. Default: all.
alongsidelist of xarray.DataArrayNoneFurther arrays with the same dimensions (e.g. the density next to the vorticity), animated side by side in sync, each with its own color limits and the same selection and options.
backend('matplotlib', 'plotly')"matplotlib"Draw with Matplotlib, or as an interactive Plotly figure with a slider (in result.fig; needs plotly, see plasma_plots.plotly_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

matplotlib.animation.FuncAnimation or PlotResult
The animation; with backend="plotly" a result whose Plotly figure has a slider and Play/Pause buttons.

Examples

>>> n.plasma.plot.animation(
... coords="physical", plane="XY", eta3=0, levels=[0.2]
... )
>>> vorticity.plasma.plot.animation(alongside=[density], eta3=0)

framesmethod#

def frames(directory, *, x: str | None = None, y: str | None = None, sweep: str = 't', coords: Coordinates = 'logical', plane: Plane = 'XY', vmin=None, vmax=None, shared_clim: bool = True, cmap: str | None = None, equal_aspect: bool | None = None, title: str | None = None, symmetric: bool = False, robust: bool = False, levels=None, fill: bool = True, overlays: dict | None = None, xlabel: str | None = None, ylabel: str | None = None, colorbar_label: str | None = None, step: int = 1, prefix: str = 'frame', dpi: int = 110, **selection)

Export the sweep as PNG frames.

Equivalent to plot.view(...).save_frames(directory); see view() for the shared options.

Parameters

NameTypeDefaultDescription
directorystr or pathlib.PathrequiredThe directory to write into; created if needed.
xstrNoneThe dimension along the horizontal axis (logical coordinates). Default: the first of the two remaining dimensions.
ystrNoneThe dimension along the vertical axis. Default: the second remaining dimension.
sweepstr't'The dimension stepped through by panels, the viewer’s slider, animations and exported frames. Default: "t".
coords('logical', 'physical')"logical"Draw over the logical coordinates, or over the mapped physical coordinates (X, Y, Z). Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ', 'X1X2')"XY"The physical plane, with coords="physical": "RZ" uses R = √(X² + Y²), "X1X2" GVEC’s reference coordinates. Default: "XY".
vminfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
vmaxfloatNoneExplicit color limits; each overrides its limit with or without shared_clim.
shared_climboolTrueFix the color limits over all selected data, including frames omitted by a panel layout or export step; False rescales each frame. Default: True.
cmapstrNoneThe colormap. Default: the Struphy style’s.
equal_aspectboolNoneEqual axis scales. Default: True for physical coordinates, else False.
titlestrNoneThe title. Default: the array’s label.
symmetricboolFalseCenter the color limits on zero, for perturbations with a diverging cmap. Default: False.
robustboolFalseTake the color limits from the 1st/99th percentiles, so a few outliers do not wash out the rest. Default: False.
levelsint or sequence of floatNoneContour lines of the field on top, e.g. an interface or flux surfaces: a number of evenly spaced levels, or explicit values. Default: none.
fillboolTrueDraw the colored field; with False only the levels lines are drawn, colored by cmap. Default: True.
overlaysdictNoneFurther elements on top: contours_of (a second field whose contour lines are drawn, e.g. the flux function over the current; with contour_levels, contour_color), boundary=True (the grid’s outline), grid_lines=n (every n-th grid line), lines (label to (x, y) or a function y(x), e.g. characteristics on a space-time map) and points (label to (x, y)), in line_color and point_color (white by default, for dark colormaps).
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s name and units.
ylabelstrNoneThe vertical axis label. Default: the coordinate’s name and units.
colorbar_labelstrNoneThe color bar label. Default: the array’s label and units.
stepint1Export every step-th element of the sweep. Default: 1.
prefixstr'frame'The file names are <prefix>_0000.png, <prefix>_0001.png, … Default: "frame".
dpiint110The resolution of the images. Default: 110.
**selection{}Every dimension but x, y and sweep: an integer is a position (-1 the last), a float the nearest coordinate value. Checked now; a name that is not a dimension raises TypeError.

Returns

list of str
The paths of the written files.

Examples

>>> phi.plasma.plot.frames("frames", x="eta1", y="eta2", eta3=0, step=5)

trajectoriesmethod#

def trajectories(max_markers: int = 200, show_paths: bool | None = None, ax=None, backend: Backend | None = None)

Plot the three-dimensional paths of saved markers, for an orbit product.

Parameters

NameTypeDefaultDescription
max_markersint200Draw only the first max_markers markers. Default: 200.
show_pathsboolNoneDraw each marker’s path, not only its last position. Default: True for up to 200 markers.
axmpl_toolkits.mplot3d.Axes3DNoneA 3-D axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the 3-D axes and the drawn artists.

poincaremethod#

def poincare(seeds=8, turns: float | None = None, section: float | None = None, coords: str = 'physical', color_by: str | None = 'line', islands: bool = False, boundary: xr.DataArray | None = None, ax=None, backend: Backend | None = None, **selection)

Trace field lines of this vector field and plot their Poincaré section.

A convenience for ArrayAnalysis.field_lines() followed by DatasetPlots.poincare(); keep the traced lines (result.data["lines"]) to plot them again, cut another plane or sample a field along them.

Parameters

NameTypeDefaultDescription
seeds(int, dict, array_like or xarray.Dataset)8Where the lines start; see plasma_plots.fieldlines.trace_field_lines(). Default: 8 along the radius.
turnsfloatNoneHow many toroidal transits to trace. Default: 20.
sectionfloatNoneThe toroidal logical coordinate of the plane. Default: the first grid value.
coords('physical', 'logical')"physical"Draw R against z (physical), or the poloidal angle against the radial logical coordinate (logical). Default: "physical".
color_by('line', 'iota', 'classification', 'connection_length', None)"line"One color per line (cycling), a color bar over each line’s rotational transform or connection length, or the classes of classify_field_lines() (surface, island, chaotic) with a legend; None for one color. Default: "line".
islandsboolFalseLabel the island chains with their n/m and widths. Default: False.
boundaryxarray.DataArrayNoneA field with physical coordinates whose outermost surface is drawn at the section (physical coordinates only).
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The other dimensions, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the scatters; data["lines"] holds the traced lines, data["section"] the punctures.

Examples

>>> B.plasma.plot.poincare(seeds=12, turns=100, t=-1)
>>> B.plasma.plot.poincare(color_by="classification", islands=True, t=-1)

surface_mapmethod#

def surface_map(x: str | None = None, y: str | None = None, iota=None, lines: xr.Dataset | None = None, count: int = 6, start: float = 0.0, turns: float | None = 2.0, line_color: str = 'w', ax=None, backend: Backend | None = None, **options)

Plot this quantity on one flux surface, unfolded over the angles, with field lines.

Select the surface and the time by keyword, e.g. rho=0.5 or eta1=0.5, t=-1. Field lines are straight lines of slope ι in straight-field-line angles (Boozer, PEST), or traced lines (ArrayAnalysis.field_lines()) on any grid.

Parameters

NameTypeDefaultDescription
xstrNoneThe toroidal angle. Default: the toroidal logical dimension.
ystrNoneThe poloidal angle. Default: the poloidal logical dimension.
iotafloat or xarray.DataArrayNoneThe rotational transform of the surface, or its profile over the radial coordinate, at whose value in data’s coordinates it is interpolated. Draws count straight field lines. Default: none.
linesxarray.DatasetNoneTraced lines (trace_field_lines()), drawn over the angles as they are, every line in the Dataset. Default: none.
countint6The number of straight lines, equally spaced in the poloidal angle. Default: 6.
startfloat0.0The poloidal angle of the first straight line at the left edge. Default: 0.
turnsfloat2.0How many toroidal transits of each traced line to draw (a long line covers an irrational surface completely); None for all. Default: 2.
line_colorstr'w'The color of the field lines. Default: white.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**options{}The remaining dimensions to select (an integer is a position, a float the nearest value), and the options of plasma_plots.plotting.plot_slice() (cmap, levels, overlays, …).

Returns

PlotResult
The figure, the axes, the mesh and the lines; data["iota"] holds the ι drawn.

Examples

>>> boozer.mod_B.plasma.plot.surface_map(rho=0.5, iota=boozer.iota, count=8)
>>> phi.plasma.plot.surface_map(eta1=0.5, t=-1, lines=lines)

along_field_linesmethod#

def along_field_lines(lines: xr.Dataset, *, k_parallel: bool = False, method: str = 'fft', max_lines: int = 12, ax=None, title: str | None = None, backend: Backend | None = None, **selection)

Plot this scalar field along traced field lines, one curve per line.

Parameters

NameTypeDefaultDescription
linesxarray.DatasetrequiredThe lines of ArrayAnalysis.field_lines().
k_parallelboolFalseEstimate each line’s parallel wavenumber (see parallel_wavenumber()) and put it in the legend. Default: False.
method('fft', 'crossings')"fft"The estimate’s method. Default: "fft".
max_linesint12Draw only the first max_lines lines. Default: 12.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
titlestrNoneThe title. Default: the samples’ label.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The other dimensions, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the lines; with k_parallel, data["k_parallel"].

Examples

>>> phi.plasma.plot.along_field_lines(lines, k_parallel=True, t=-1)

critical_pointsmethod#

def critical_points(x: str | None = None, y: str | None = None, coords: Coordinates = 'logical', plane: Plane = 'XY', levels=14, cmap=None, label_values: bool = False, ax=None, backend: Backend | None = None, **selection)

Plot the contours of this flux function with its O-points and X-points.

Parameters

NameTypeDefaultDescription
xstrNoneThe dimension along the horizontal axis. Default: the first of the plane.
ystrNoneThe dimension along the vertical axis. Default: the second of the plane.
coords('logical', 'physical')"logical"Logical coordinates, or the physical plane. Default: "logical".
plane('XY', 'XZ', 'YZ', 'RZ')"XY"The physical plane. Default: "XY".
levelsint or sequence of float14Contour lines of the flux, as for [plot_slice()][plot_slice]. Default: 14.
cmapstr or matplotlib.colors.ColormapNoneThe colormap. Default: "RdBu_r".
label_valuesboolFalseWrite the flux value next to each point. Default: False.
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}The other dimensions, e.g. t=-1: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes, the mesh, the contours and the scatters; data["points"] holds the points.

Examples

>>> A = B.plasma.analysis.flux_function()
>>> A.plasma.plot.critical_points(t=-1, eta3=0)
>>> A.plasma.plot.critical_points(coords="physical", t=-1, eta3=0)

boozer_spectrummethod#

def boozer_spectrum(top: int = 8, helicity=None, log: bool = True, angles: str = 'boozer', x_of=None, xlabel: str | None = None, title: str | None = None, backend: Backend | None = None, **selection)

Plot the strongest Boozer harmonics of this |B| over the radius, and the quasi-symmetry error.

Parameters

NameTypeDefaultDescription
topint8The number of harmonics drawn, strongest first. Default: 8.
helicity('QA', 'QP', 'QH')"QA"The symmetry to judge against (see quasisymmetry_error()). Default: none.
logboolTrueA logarithmic amplitude axis. Default: True.
angles('boozer', 'any')"boozer"As for boozer_spectrum().
x_ofcallableNoneMaps the radial coordinate to the plotted axis, e.g. lambda rho: a * rho.
xlabelstrNoneThe horizontal axis label. Default: the coordinate’s.
titlestrNoneThe title. Default: the harmonics’ label.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Other dimensions to select first: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the lines; data holds the amplitudes and the error.

Examples

>>> boozer.mod_B.plasma.plot.boozer_spectrum(top=8, helicity="QA")

A configured array view, shared by static, interactive and exported plots.

slicemethod#

def slice(ax=None, backend: Backend | None = None, **selection)

Draw a snapshot, e.g. view.slice(t=-1).

With shared_clim, the color limits come from all of the view’s data, so the snapshot uses the same scale as its panels, animation and exported frames.

Parameters

NameTypeDefaultDescription
axmatplotlib.axes.AxesNoneThe axes to draw into. Default: a new figure.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
**selection{}Further dimensions to select, e.g. t=-1, in addition to (or overriding) the view’s own selection: an integer is a position, a float the nearest coordinate value.

Returns

PlotResult
The figure, the axes and the drawn mesh.

Examples

>>> view.slice(t=-1)

panelsmethod#

def panels(nrows=3, ncols=4, backend: Backend | None = None)

Draw snapshots spread evenly along the sweep.

Parameters

NameTypeDefaultDescription
nrowsint3The number of rows of panels. Default: 3.
ncolsint4The number of columns of panels. Default: 4.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Draw with Matplotlib, as an interactive Plotly figure, or as TikZ/pgfplots code for LaTeX (in result.fig; needs plotly or maxplotlib, see plasma_plots.plotly_backend and plasma_plots.tikz_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

PlotResult
The figure, the array of axes and the drawn meshes.

Examples

>>> view.panels(nrows=2, ncols=3)

viewermethod#

def viewer(backend: Backend | None = None)

Create a viewer with sliders for the unselected dimensions.

Keep a reference to the returned viewer.

Parameters

NameTypeDefaultDescription
backend('matplotlib', 'plotly')"matplotlib"Draw with Matplotlib, or as an interactive Plotly figure with a slider (in result.fig; needs plotly, see plasma_plots.plotly_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

plasma_plots.plotting.InteractiveSliceViewer or PlotResult
The viewer, with this view’s rendering options; with backend="plotly" a result whose Plotly figure has one slider (one unselected dimension at most).

animationmethod#

def animation(interval=100, step=1, max_frames=None, alongside=None, backend: Backend | None = None)

Create a Matplotlib animation using this view’s rendering options.

Keep a reference to the returned animation.

Parameters

NameTypeDefaultDescription
intervalint100The delay between frames, in milliseconds. Default: 100.
stepint1Use every step-th value of the sweep. Default: 1.
max_framesintNoneKeep at most this many frames, evenly spaced over those step leaves (the first and last included), e.g. to keep a Plotly animation small. Default: all.
alongsidelist of xarray.DataArrayNoneFurther arrays with the same dimensions, animated side by side in sync, each with its own color limits.
backend('matplotlib', 'plotly')"matplotlib"Draw with Matplotlib, or as an interactive Plotly figure with a slider (in result.fig; needs plotly, see plasma_plots.plotly_backend). Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.

Returns

matplotlib.animation.FuncAnimation or PlotResult
The animation; with backend="plotly" a result whose Plotly figure has a slider and Play/Pause buttons.

Examples

>>> view.animation(step=2)

save_framesmethod#

def save_frames(directory, *, step=1, prefix='frame', dpi=110)

Export PNG frames using this view’s rendering options.

Parameters

NameTypeDefaultDescription
directorystr or pathlib.PathrequiredThe directory to write into.
stepint1Use every step-th value of the sweep. Default: 1.
prefixstr'frame'The start of each file name. Default: "frame".
dpiint110The resolution of the PNGs. Default: 110.

Returns

list of str
The paths of the written files.

Examples

>>> view.save_frames("frames")