question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plotly graph does not show up when using the pdflatex builder

See original GitHub issue

Describe the problem

When I build a book with the pdflatex builder, plotly graphs are seemingly not included in the pdf by default. A workaround can be done to fix this by changing the plotly render method to png as follows

import plotly.io as pio
pio.renderers.default = "png"

but the pdflatex builder then expects the generated pngs to be in the root of _build\jupyter_execute. This is not the case if the .ipynb is in a subfolder of the book directory. In the case of the notebook being in a subfolder, the png is generated in _build\jupyter_execute\subfolder\ and therefor is not found by the builder

Link to your repository or website

No response

Steps to reproduce

Standard

  1. Create notebook with plotly graph
import plotly.graph_objects as go
ifig = go.Figure(go.Scatter(x=[1,2], y=[1,2]))
ifig.show()
  1. Create a toc and _config that includes
sphinx:
  config:
    html_js_files:
    - https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js
  1. Build the book
jupyter-book build mybook\ --builder pdflatex
  1. Open the pdf and see that no plotly figure is present

PNG

  1. Create a notebook in a subfolder (mybook\folder\notebook.ipynb)
  2. Create plotly graph in notebook
  3. Add plotly renderer line to notebook
import plotly.io as pio
pio.renderers.default = "png"
  1. Build the book
  2. See the following warning in the build
WARNING: image file not readable: .../mybook/_build/jupyter_execute/notebook_15_1.png
  1. See that the file is not in this location and is rather in _build/jupyter_execute/folder/notebook_15_1.png
  2. Open the pdf and see that no plotly figure is present

The version of Python you’re using

3.8.5

Your operating system

Windows 10

Versions of your packages

Jupyter Book : 0.11.2 External ToC : 0.2.2 MyST-Parser : 0.13.7 MyST-NB : 0.12.3 Sphinx Book Theme : 0.1.1 Jupyter-Cache : 0.4.2 NbClient : 0.5.3

Additional context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mmckycommented, Aug 9, 2021

thanks for this well documented issue @andrewellis55 – will take a look at this. (cc: @AakashGfude)

We haven’t explicitly built support for plotly into the pdflatex builder as there are a lot of object types. Your suggestion to convert items to png in the code is a solution I use a lot in house as well.

Do you know if plotly returns a png as an alternative representation in the executed ipynb? If it does you can change the render_priority to use the png instead of the returned javascript object.

https://jupyterbook.org/content/code-outputs.html?highlight=render_priority#render-priority

0reactions
holongatecommented, Feb 2, 2022

Thanks for the update, I appreciate.

In between, I patched the 0.13 version by hand (it is really 2 lines) inside a container I will use for the final PDF generation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jupyter Notebook Plotly Charts Not Rendering in PDF via Latex
I have tried adding fig.show(render='pdf') and thats does not work the notebook converts to pdf but still no chart. I do not see...
Read more >
Troubleshooting in Python - Plotly
New to Plotly? Plotly is a free and open-source graphing library for Python. We recommend you read our Getting Started guide for the...
Read more >
Chart Studio Tutorials - Plotly
Chart Studio is the easiest way to graph and share your data.
Read more >
Interactive data analysis with figurewidget ipywidgets in Python
autotypenumbers | Using "strict" a numeric string in trace data | is not ... how bars at the same location | coordinate are...
Read more >
Displaying figures in Python - Plotly
Displaying Figures using Plotly's Python graphing library ... This renderer is intended for use in the classic Jupyter Notebook (not JupyterLab).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found