Convert plotly figures to LaTeX / tikz figures
Project description
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
- Generate the figure with Plotly,
- Invoke
tikzplotly
to convert the figure to tikz code :
import tikzplotly
tikzplotly.save("figure.tex", fig)
- 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.
- More details in doc/NB.md.
References
- plotly
- PGFPlots (with manual)
- PGF/TikZ
- tikzplotlib : a similar project for matplotlib figures from which this one is inspired.
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
Built Distribution
File details
Details for the file tikzplotly-0.1.3.tar.gz
.
File metadata
- Download URL: tikzplotly-0.1.3.tar.gz
- Upload date:
- Size: 29.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43d11ac820459aa492da20d95b756a10262f431d896847d2d7a7a6099ea7fe7f |
|
MD5 | 09322b2b1f53ea0c94811e0baa58ec57 |
|
BLAKE2b-256 | c8481fbdb0812a0747624ff7e65fe03e1ed295dd4933350516841fe564edd304 |
File details
Details for the file tikzplotly-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: tikzplotly-0.1.3-py3-none-any.whl
- Upload date:
- Size: 24.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 520f366bc515232d21d84d126ae55f9fa1dbc0a1f3ee4332cb9551b5a3452467 |
|
MD5 | 558c1984104c52e5d01e84501ffea9a1 |
|
BLAKE2b-256 | 159421e6a34b0a2be8cc452f12e02655b7fa5d3dfb93dcf6412d679a3c5fdef7 |