# plasma_plots.styles

*module*

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 (see [`plasma_plots.hero.from_array()`][plasma_plots.hero.from_array] for an
  animated SVG and [`plasma_plots.plotly_backend.bare()`][plasma_plots.plotly_backend.bare] for a Plotly figure).

[`set_style()`][plasma_plots.styles.set_style] sets the style of every later plot; [`style()`][plasma_plots.styles.style] sets it for a ``with`` block
only, where it also applies to plain Matplotlib figures created inside the block.

**Examples**

```pycon
>>> 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")
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L1-L1)

## plasma_plots.styles.ACCENT

*attribute* · *module attribute*

```python
ACCENT = '#2a78d6'
```

The accent colour of the max-models docs, the first line colour of the ``"bare"`` style.

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L44-L44)

## plasma_plots.styles.DEFAULT

*attribute* · *module attribute*

```python
DEFAULT = {'figure.figsize': (8.0, 5.0), 'figure.dpi': 110, 'axes.grid': True, 'grid.alpha': 0.3, 'axes.titlesize': 'medium', 'legend.frameon': False, 'image.cmap': 'viridis'}
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L50-L58)

## plasma_plots.styles.PALETTE

*attribute* · *module attribute*

```python
PALETTE = ('#0072B2', '#E69F00', '#009E73', '#D55E00', '#CC79A7', '#56B4E9', '#F0E442', '#000000')
```

The Okabe–Ito palette: eight colours that colour-blind readers tell apart.

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L32-L41)

## plasma_plots.styles.STYLES

*attribute* · *module attribute*

```python
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.

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L62-L114)

## plasma_plots.styles.get_style

*function*

```python
def get_style() -> str
```

Return the name of the current style.

**Returns**

- (`str`) — One of the keys of [`STYLES`][plasma_plots.styles.STYLES].

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L134-L142)

## plasma_plots.styles.set_style

*function*

```python
def set_style(name: str = 'default', **overrides) -> None
```

Set the style of every later plot.

**Parameters**

- `name` (`('default', 'colorblind', 'paper', 'dark', 'bare')`) (default: `"default"`) — The style (see [`STYLES`][plasma_plots.styles.STYLES]). Default: ``"default"``, the plots' usual style.
- `**overrides` (default: `{}`) — 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 ``rcParams`` name.

> **See Also**
>
> [`style()`][plasma_plots.styles.style] : The same for a ``with`` block only.

**Examples**

```pycon
>>> plasma_plots.set_style("colorblind")
>>> plasma_plots.set_style("paper", figure_figsize=(3.4, 3.0))
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L183-L209)

## plasma_plots.styles.style

*function*

```python
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` (`('default', 'colorblind', 'paper', 'dark', 'bare')`) (default: `"default"`) — The style (see [`STYLES`][plasma_plots.styles.STYLES]).
- `**overrides` (default: `{}`) — Matplotlib ``rcParams`` to change on top of the style, with dots written as underscores, e.g. ``figure_dpi=150``.

**Yields**

- (`dict`) — The ``rcParams`` in effect.

**Raises**

- `ValueError` — If there is no style of that name, or an override is not a Matplotlib ``rcParams`` name.

**Examples**

```pycon
>>> with plasma_plots.style("dark"):
...     energy.plasma.plot.timeseries().save("energy_dark.png")
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L212-L258)

## plasma_plots.styles.style_params

*function*

```python
def style_params(name: str | None = None) -> dict
```

Return the Matplotlib ``rcParams`` of a style.

**Parameters**

- `name` (`str`) (default: `None`) — The style. Default: the current one, with the overrides given to [`set_style()`][plasma_plots.styles.set_style] or [`style()`][plasma_plots.styles.style].

**Returns**

- (`dict`) — The parameters, to pass to ``matplotlib.pyplot.rc_context``.

**Raises**

- `ValueError` — If there is no style of that name.

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L145-L167)

## plasma_plots.styles.to_dark

*function*

```python
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**

- `fig` (`matplotlib.figure.Figure`) — The figure; it is changed.
- `text` (`str`) (default: `_DARK_TEXT`) — The colour of text and of black lines. Default: the ``"dark"`` style's text colour.
- `axes` (`str`) (default: `'#8a8d96'`) — The colour of spines and ticks. Default: a mid grey.
- `background` (`str`) (default: `_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**

```pycon
>>> result = energy.plasma.plot.timeseries()
>>> result.fig.savefig("energy.png")
>>> to_dark(result.fig).savefig("energy.dark.png", transparent=True)
```

[View source](https://github.com/max-models/plasma-plots/blob/devel/src/plasma_plots/styles.py#L292-L369)
