Skip to content

plasma_plots.figures

Several plots in one figure, with any backend: plasma_plots.figure(...).

with plasma_plots.figure(2, 1, sharex=True, backend=“plotly”) as fig: … energy.plasma.plot.timeseries(fit=(0.0, 5.0), ax=fig[0]) … drift.plasma.plot.timeseries(logy=True, ax=fig[1]) fig.save(“energies.html”)

Every plot method that takes ax= draws into one panel. The figure is drawn with Matplotlib and, with backend="plotly", converted to one Plotly figure when the block ends, so the panels share zoom where their axes are shared and every panel keeps its colorbar and legend; with backend="tikz", to one TikZ/pgfplots figure (see plasma_plots.tikz_backend).

Classes

NameDescription
FigureA figure of several panels, made by figure().

Functions

NameDescription
figureCompose several plots into one figure, drawn with Matplotlib, or as one Plotly or TikZ figure.

Figureclass#

class Figure(nrows, ncols, *, backend, sharex, sharey, figsize, title, **options)

A figure of several panels, made by figure().

Index it for a panel’s Matplotlib axes (fig[0], fig[1, 2]) and pass that as ax= to any plot method. After the with block, it saves and shows like a PlotResult.

Parameters

NameTypeDefaultDescription
nrowsintrequiredThe number of rows and columns of panels.
ncolsintrequiredThe number of rows and columns of panels.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"How the figure is finished; None for the default (see plasma_plots.set_backend()).
sharexbool or {'row', 'col', 'all'}requiredShare the horizontal or vertical axes.
shareybool or {'row', 'col', 'all'}requiredShare the horizontal or vertical axes.
figsize(float, float) or NonerequiredThe size in inches; None for one from the number of panels.
titlestr or NonerequiredA title above all panels.
**options{}Passed on to matplotlib.pyplot.subplots.

Attributes

NameTypeDescription
axesnumpy.ndarray of matplotlib.axes.Axes or NoneThe panels, (nrows, ncols); None on MPI ranks other than 0, where nothing is drawn.
resultslist of PlotResultWhat the plot methods drawn into the panels returned, in order (e.g. their fit_results).

axesattributeinstance attribute#

axes = axes

backendattributeinstance attribute#

backend = backend

resultsattributeinstance attribute#

results = []

figproperty#

fig

The finished Matplotlib, Plotly or TikZ figure.

resultproperty#

result

The figure, as a PlotResult.

After the with block the finished figure; inside it, the figure as drawn so far, so that fig.save(...) works in either place.

Returns

PlotResult or SkippedPlot
The figure, Matplotlib, Plotly or TikZ, with the fit_results of every panel.

savemethod#

def save(path, **kwargs)

Save the figure, as PlotResult.save does.

Inside the with block it saves the panels drawn so far.

Parameters

NameTypeDefaultDescription
pathstr or pathlib.PathrequiredThe file to write; its extension picks the format.
**kwargs{}Passed to PlotResult.save.

Returns

str
The path written.

showmethod#

def show()

Show the finished figure.

Returns

Figure
This figure.

figurefunction#

def figure(nrows: int = 1, ncols: int = 1, *, backend: str | None = None, sharex: bool | str = False, sharey: bool | str = False, figsize=None, title: str | None = None, **options) -> Figure

Compose several plots into one figure, drawn with Matplotlib, or as one Plotly or TikZ figure.

Use it as a with block: every plot method given ax=fig[i] draws into panel i; at the end of the block the figure is finished, and with backend="plotly" or backend="tikz" converted once.

Parameters

NameTypeDefaultDescription
nrowsint1The number of rows of panels. Default: 1.
ncolsint1The number of columns of panels. Default: 1.
backend('matplotlib', 'plotly', 'tikz')"matplotlib"Finish the figure as a Matplotlib figure, as an interactive Plotly figure, or as a TikZ/pgfplots figure for LaTeX. Default: the one set with plasma_plots.set_backend(), "matplotlib" unless changed.
sharexbool or {'row', 'col', 'all'}FalseShare the horizontal axes (and their zoom, in Plotly), as for matplotlib.pyplot.subplots. Default: False.
shareybool or {'row', 'col', 'all'}FalseShare the vertical axes. Default: False.
figsize(float, float)NoneThe size in inches. Default: from the number of panels.
titlestrNoneA title above all panels. Default: none.
**options{}Passed on to matplotlib.pyplot.subplots, e.g. gridspec_kw={"height_ratios": [3, 1]}.

Returns

Figure
The figure; index it for the panels’ axes, and save or show it after the block.

Examples

>>> with plasma_plots.figure(2, 1, sharex=True, backend="plotly") as fig:
... energy.plasma.plot.timeseries(fit=(0.0, 5.0), ax=fig[0])
... drift.plasma.plot.timeseries(logy=True, ax=fig[1])
>>> fig.save("energies.html")
>>> fig.results[0].fit_results[0].rate