Dear all,
I am using Plot.ly offline in Jupyter Notebooks in Python. See the example code below. When exporting the notebook to LaTeX using nbconvert, the interactive PlotLy figure gets converted to PNG. Is there a way to make it export to vector graphics instead? (SVG, EPS or PDF). Is the PNG conversion done by nbconvert itself or by plotly or orca?
I know that I could either:
- use the write_image method to save the figure to SVG, EPS or PDF. This is what I would use for publications, but for regular documents, I would like to avoid having to save figures manually before generating the LaTeX files
- use to_image(fig, format=βsvgβ) and then display the SVG using the IPython.display.SVG method. However, nbconvert fails at the moment because of SVG, the pull request is still pending: do not pipe non-json data through json.dumps by sgsaenger Β· Pull Request #910 Β· jupyter/nbconvert Β· GitHub
The code I use:
import plotly.offline as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
trace = go.Scatter(
x = df.loc['A']['X'],
y = df.loc['A']['Y'],
mode='markers'
)
data = [trace]
layout = go.Layout(
title = 'A',
xaxis = dict(
title = 'X'
),
yaxis = dict(
title = 'Y'
)
)
fig = dict(data=data, layout=layout)
py.iplot(fig)
I use the following command in the terminal to convert the notebook to LaTeX:
jupyter nbconvert --template=myTemplate.tplx --to=latex myNotebook.ipynb
My setup:
- Ubuntu 18.04 x64
- conda environment containing:
- plotly 3.7.0 from plotly conda channel
- plotly-orca 1.2.1 from plotly conda channel
- notebook 5.7.6 from conda-forge channel
- jupyterlab 0.35.4 from conda-forge channel
- nbconvert 5.4.1 from conda-forge channel
Thank you,
Best regards
GorgiAstro