plasma_plots.styles
Named plot styles and a colour-blind-safe palette: plasma_plots.set_style.
Every Matplotlib plot of plasma-plots draws with the current style. "default" is the style the
plots always had; the others change it:
"colorblind": the default with the Okabe–Ito palette ([PALETTE][PALETTE]) as the line colours, which stay distinct for the common forms of colour blindness."paper": small figures with small text for a journal column, in the same palette."dark": light lines and text on a dark background, for slides and dark docs pages."bare": no axes, ticks, labels or titles, a transparent background and the accent colour first, for header pictures and front pages (seeplasma_plots.hero.from_array()for an animated SVG andplasma_plots.plotly_backend.bare()for a Plotly figure).
set_style() sets the style of every later plot; style() sets it for a with block
only, where it also applies to plain Matplotlib figures created inside the block.
Examples
>>> import plasma_plots>>> plasma_plots.set_style("colorblind")>>> with plasma_plots.style("dark"):... phi.plasma.plot.slice(t=-1, eta3=0).save("phi_dark.png")Attributes
Functions
| Name | Description |
|---|---|
get_style | Return the name of the current style. |
set_style | Set the style of every later plot. |
style | Draw with a style inside a with block. |
style_params | Return the Matplotlib rcParams of a style. |
to_dark | Recolour a drawn Matplotlib figure for a dark page, in place. |
ACCENTattributemodule attribute#
ACCENT = '#2a78d6'The accent colour of the max-models docs, the first line colour of the "bare" style.
DEFAULTattributemodule attribute#
PALETTEattributemodule attribute#
PALETTE = ('#0072B2', '#E69F00', '#009E73', '#D55E00', '#CC79A7', '#56B4E9', '#F0E442', '#000000')The Okabe–Ito palette: eight colours that colour-blind readers tell apart.
STYLESattributemodule attribute#
STYLES = {
'default': DEFAULT,
'colorblind': _COLORBLIND,
'paper': {
: _COLORBLIND,
'figure.figsize': (3.4, 2.4),
'figure.dpi': 200,
'font.size': 8,
'axes.titlesize': 8,
'axes.labelsize': 8,
'xtick.labelsize': 7,
'ytick.labelsize': 7,
'legend.fontsize': 7,
'lines.linewidth': 1.2,
'savefig.dpi': 300
},
'dark': {
: DEFAULT,
'axes.prop_cycle': cycler(color=(*PALETTE[:7], _DARK_TEXT)),
'figure.facecolor': _DARK_BACKGROUND,
'axes.facecolor': _DARK_BACKGROUND,
'savefig.facecolor': _DARK_BACKGROUND,
'axes.edgecolor': '#8a8d96',
'axes.labelcolor': _DARK_TEXT,
'axes.titlecolor': _DARK_TEXT,
'text.color': _DARK_TEXT,
'xtick.color': _DARK_TEXT,
'ytick.color': _DARK_TEXT,
'grid.color': '#ffffff',
'grid.alpha': 0.15,
'legend.labelcolor': _DARK_TEXT
},
'bare': {
: DEFAULT,
'axes.prop_cycle': cycler(color=(ACCENT, *PALETTE[1:])),
'axes.grid': False,
'axes.spines.left': False,
'axes.spines.right': False,
'axes.spines.top': False,
'axes.spines.bottom': False,
'xtick.bottom': False,
'xtick.labelbottom': False,
'ytick.left': False,
'ytick.labelleft': False,
'axes.labelcolor': 'none',
'axes.titlecolor': 'none',
'figure.facecolor': 'none',
'axes.facecolor': 'none',
'savefig.transparent': True,
'lines.linewidth': 2.0,
'legend.frameon': False
}
}The named styles: Matplotlib rcParams per name.
get_stylefunction#
def get_style() -> strReturn the name of the current style.
set_stylefunction#
def set_style(name: str = 'default', **overrides) -> NoneSet the style of every later plot.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | ('default', 'colorblind', 'paper', 'dark', 'bare') | "default" | The style (see STYLES). Default: "default", the plots’ usual style. |
**overrides | {} | Matplotlib rcParams to change on top of the style, with dots written as underscores,
e.g. figure_dpi=150. |
Raises
ValueError- If there is no style of that name, or an override is not a Matplotlib
rcParamsname.
Examples
>>> plasma_plots.set_style("colorblind")>>> plasma_plots.set_style("paper", figure_figsize=(3.4, 3.0))stylefunction#
def style(name: str, **overrides)Draw with a style inside a with block.
Inside the block the style also applies to plain Matplotlib figures, e.g. a colorbar or an annotation added to a plot of plasma-plots.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | ('default', 'colorblind', 'paper', 'dark', 'bare') | "default" | The style (see STYLES). |
**overrides | {} | Matplotlib rcParams to change on top of the style, with dots written as underscores,
e.g. figure_dpi=150. |
Yields
dict- The
rcParamsin effect.
Raises
ValueError- If there is no style of that name, or an override is not a Matplotlib
rcParamsname.
Examples
>>> with plasma_plots.style("dark"):... energy.plasma.plot.timeseries().save("energy_dark.png")style_paramsfunction#
def style_params(name: str | None = None) -> dictReturn the Matplotlib rcParams of a style.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
name | str | None | The style. Default: the current one, with the overrides given to set_style() or
style(). |
Returns
dict- The parameters, to pass to
matplotlib.pyplot.rc_context.
Raises
ValueError- If there is no style of that name.
to_darkfunction#
def to_dark(fig, *, text: str = _DARK_TEXT, axes: str = '#8a8d96', background: str = _DARK_BACKGROUND)Recolour a drawn Matplotlib figure for a dark page, in place.
For a dark variant of a figure that was drawn for a white page (e.g. x.dark.png next to
x.png), without drawing it again: black and dark grey text, lines, markers, edges and
hatches become text, the spines and ticks axes, white becomes background, and the
figure and axes backgrounds become transparent. Colormapped artists (images, meshes,
scatters coloured by a value) and other colours stay as they are. Save it with
transparent=True to show the page behind it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
fig | matplotlib.figure.Figure | required | The figure; it is changed. |
text | str | _DARK_TEXT | The colour of text and of black lines. Default: the "dark" style’s text colour. |
axes | str | '#8a8d96' | The colour of spines and ticks. Default: a mid grey. |
background | str | _DARK_BACKGROUND | The colour for white (e.g. white markers or masks). Default: the "dark" style’s
background. |
Returns
matplotlib.figure.Figure- The same figure.
Examples
>>> result = energy.plasma.plot.timeseries()>>> result.fig.savefig("energy.png")>>> to_dark(result.fig).savefig("energy.dark.png", transparent=True)