# plasma_plots.tikz_backend

*module*

LaTeX versions of the plots, as TikZ/pgfplots code: ``backend="tikz"``.

Every accessor plot that draws with Matplotlib (``array.plasma.plot.*``, ``dataset.plasma.plot.*``,
``out.plot.*``) takes ``backend="tikz"``. The plot is drawn with Matplotlib as usual, off screen,
and the drawn figure is converted by `maxplotlib <https://github.com/max-models/maxplotlib>`_
([`maxplotlib.backends.tikzfigure.figure_to_tikz()`][maxplotlib.backends.tikzfigure.figure_to_tikz]) into a
`tikzfigure <https://github.com/max-models/tikzfigure>`_ figure of pgfplots axes: every panel at
the place and size it has in the Matplotlib figure, with its limits, log scales, labels and title
typeset by LaTeX, its ticks, legend and colorbar. Lines, markers, fits, reference lines, bars,
spans, contour lines and text are pgfplots code; meshes (also on mapped grids), images and the
color strips of colorbars are images that Matplotlib renders, placed with ``\addplot graphics``.

>>> result = energy.plasma.plot.timeseries(fit=(0.0, 5.0), backend="tikz")
>>> # a standalone LaTeX document; also .tikz, .pdf, .png
>>> result.save("energy.tex")
>>> result.fig  # a tikzfigure.TikzFigure
>>> print(result.fig.generate_tikz())  # the tikzpicture, to paste into a paper
>>> plasma_plots.set_backend("tikz")  # the default for every plot from now on

Saving as ``.tikz`` writes the ``tikzpicture`` (for ``\input`` into a document that loads
``pgfplots``), ``.tex`` a standalone document; both write the images the figure refers to next to
the file. ``.pdf`` and ``.png`` compile the figure with ``pdflatex``. Text is converted from
Matplotlib's: mathtext (``$\omega/\omega_{ci}$``) is LaTeX math, and plain text is escaped.

Animations and interactive viewers have no TikZ version. maxplotlib is optional:
``pip install "plasma-plots[tikz]"``.

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

## plasma_plots.tikz_backend.OPTIONS

*attribute* · *module attribute*

```python
OPTIONS = {'raster_dpi': 300, 'max_markers': 2000, 'max_items': 500, 'max_points': 20000}
```

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

## plasma_plots.tikz_backend.to_tikz

*function*

```python
def to_tikz(figure, **options)
```

Convert a drawn Matplotlib figure into a TikZ/pgfplots figure.

**Parameters**

- `figure` (`matplotlib.figure.Figure`) — The figure, e.g. ``result.fig`` of a plotting function.
- `**options` (default: `{}`) — Passed to [`maxplotlib.backends.tikzfigure.figure_to_tikz()`][maxplotlib.backends.tikzfigure.figure_to_tikz], over [`OPTIONS`][plasma_plots.tikz_backend.OPTIONS]: ``raster_dpi``, ``max_markers``, ``max_items``, ``max_points``, ``precision``.

**Returns**

- (`tikzfigure.TikzFigure`) — The figure: ``generate_tikz()`` for the ``tikzpicture``, ``savefig`` to write ``.tikz``, ``.tex``, ``.pdf`` or ``.png``.

> **See Also**
>
> [`plasma_plots.plotting.PlotResult.to_tikz()`][plasma_plots.plotting.PlotResult.to_tikz] : The same for a plot's result.

**Examples**

```pycon
>>> figure = to_tikz(plot_lineout(phi.isel(t=-1, eta2=0, eta3=0)).fig)
>>> figure.savefig("phi.tex")
```

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