Skip to main content

Convert plotly figures to LaTeX / tikz figures

Project description

logo-tikzplotly

PyPi Version PyPI pyversions

Issue

Tikzplotly

Convert plotly figures to tikz code for inclusion into PGFPlots (PGF/TikZ) figures.

This results in a tikz code, that can be easily included into your LaTeX document. This also allows to easily edit the content of the figure.

Example

The following Python code

import plotly.express as px
import tikzplotly

df = px.data.gapminder().query("continent == 'Oceania'")
fig = px.line(df, x='year', y='lifeExp', color='country', markers=True)
tikzplotly.save("example.tex", fig)

will result in the following tikz code

\pgfplotstableread{data0 Australia New_Zealand
1952 69.12 69.39
1957 70.33 70.26
1962 70.93 71.24
1967 71.1 71.52
1972 71.93 71.89
1977 73.49 72.22
1982 74.74 73.84
1987 76.32 74.32
1992 77.56 76.33
1997 78.83 77.55
2002 80.37 79.11
2007 81.235 80.204
}\dataZ

\begin{tikzpicture}

\definecolor{636efa}{HTML}{636efa}
\definecolor{EF553B}{HTML}{EF553B}

\begin{axis}[
xlabel=year,
ylabel=lifeExp,
]
\addplot+ [mark=*, solid, color=636efa, mark options={solid, draw=636efa}] table[y=Australia] {\dataZ};
\addlegendentry{Australia}
\addplot+ [mark=*, solid, color=EF553B, mark options={solid, draw=EF553B}] table[y=New_Zealand] {\dataZ};
\addlegendentry{New Zealand}
\end{axis}
\end{tikzpicture}

Installation

Tikzplotly is available from the Python Package Index, so it can be installed with pip :

pip install tikzplotly

Usage

  1. Generate the figure with Plotly,
  2. Invoke tikzplotly to convert the figure to tikz code :
import tikzplotly

tikzplotly.save("figure.tex", fig)
  1. Add the content of the generated file figure.tex to your LaTeX document :
\input{figure.tex}

To correctly compile the document, you will need to add the following packages to your preamble :

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

Note

  • This module is in development and new features are added bit by bit, when needed. If you have a feature request, please open an issue with the plotly figure you want to convert and the desired output. You can also submit a pull request with the desired feature !
  • Some feature can result in different output between the plotly figure and the tikz figure, for instance the size of markers.

References

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tikzplotly-0.1.1.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

tikzplotly-0.1.1-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file tikzplotly-0.1.1.tar.gz.

File metadata

  • Download URL: tikzplotly-0.1.1.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for tikzplotly-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f27868d96ecafa68e75868b8abd9976b9f83727e9783866566461174e546fe1f
MD5 91f878e42866eba4070a55084d9b642b
BLAKE2b-256 33e55ce97df0e8857a02e2adb279254926080001db3f663dfbff07ea7f76f780

See more details on using hashes here.

File details

Details for the file tikzplotly-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tikzplotly-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for tikzplotly-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3bec7f876a3705b1e4cc65dca02e485e1d0ddd99ce113fb55b8448e935a7a7c3
MD5 fdd0a59644aa7ff217923d3cdcbe0ba2
BLAKE2b-256 26dffa5dd6f9bc717d227e9f7b143b84d426968a77482db554c89492b327076a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page