Welcome to tikzplotlib’s documentation!

Contents:

Methods

Script to convert Matplotlib generated figures into TikZ/PGFPlots figures.

tikzplotlib.get_tikz_code(figure='gcf', filepath=None, figurewidth=None, figureheight=None, textsize=10.0, tex_relative_path_to_data=None, externalize_tables=False, override_externals=False, strict=False, wrap=True, add_axis_environment=True, extra_axis_parameters=None, extra_tikzpicture_parameters=None, dpi=None, show_info=False, include_disclaimer=True, standalone=False, float_format='{:.15g}', table_row_sep='\n')

Main function. Here, the recursion into the image starts and the contents are picked up. The actual file gets written in this routine.

Parameters:
  • figure – either a Figure object or ‘gcf’ (default).
  • figurewidth (str) – If not None, this will be used as figure width within the TikZ/PGFPlots output. If figureheight is not given, tikzplotlib will try to preserve the original width/height ratio. Note that figurewidth can be a string literal, such as '\figurewidth'.
  • figureheight (str) – If not None, this will be used as figure height within the TikZ/PGFPlots output. If figurewidth is not given, tikzplotlib will try to preserve the original width/height ratio. Note that figurewidth can be a string literal, such as '\figureheight'.
  • textsize (float) – The text size (in pt) that the target latex document is using. Default is 10.0.
  • tex_relative_path_to_data (str) – In some cases, the TikZ file will have to refer to another file, e.g., a PNG for image plots. When \input into a regular LaTeX document, the additional file is looked for in a folder relative to the LaTeX file, not the TikZ file. This arguments optionally sets the relative path from the LaTeX file to the data.
  • externalize_tables (bool) – Whether or not to externalize plot data tables into tsv files.
  • override_externals (bool) – Whether or not to override existing external files (such as tsv or images) with conflicting names (the alternative is to choose other names).
  • strict (bool) – Whether or not to strictly stick to matplotlib’s appearance. This influences, for example, whether tick marks are set exactly as in the matplotlib plot, or if TikZ/PGFPlots can decide where to put the ticks.
  • wrap (bool) – Whether '\begin{tikzpicture}' and '\end{tikzpicture}' will be written. One might need to provide custom arguments to the environment (eg. scale= etc.). Default is True.
  • add_axis_environment (bool) – Whether '\begin{axis}[...]' and '\end{axis}' will be written. One needs to set the environment in the document. If False additionally sets wrap=False. Default is True.
  • extra_axis_parameters (a list or set of strings for the pfgplots axes.) – Extra axis options to be passed (as a list or set) to pgfplots. Default is None.
  • extra_tikzpicture_parameters (a set of strings for the pfgplots tikzpicture.) – Extra tikzpicture options to be passed (as a set) to pgfplots.
  • dpi (int) – The resolution in dots per inch of the rendered image in case of QuadMesh plots. If None it will default to the value savefig.dpi from matplotlib.rcParams. Default is None.
  • show_info (bool) – Show extra info on the command line. Default is False.
  • include_disclaimer (bool) – Include tikzplotlib disclaimer in the output. Set False to make tests reproducible. Default is True.
  • standalone (bool) – Include wrapper code for a standalone LaTeX file.
  • float_format (str) – Format for float entities. Default is `"{:.15g}"`.
  • table_row_sep (str) – Row separator for table data. Default is `"\n"`.
Returns:

None

The following optional attributes of matplotlib’s objects are recognized and handled:

  • axes.Axes._tikzplotlib_anchors This attribute can be set to a list of ((x,y), anchor_name) tuples. Invisible nodes at the respective location will be created which can be referenced from outside the axis environment.
tikzplotlib.save(filepath, *args, encoding=None, **kwargs)

Same as get_tikz_code(), but actually saves the code to a file.

Parameters:
  • filepath (str) – The file to which the TikZ output will be written.
  • encoding – Sets the text encoding of the output file, e.g. ‘utf-8’. For supported values: see codecs module.
Returns:

None

Indices and tables