spatialaudio / nbsphinx

:ledger: Sphinx source parser for Jupyter notebooks
https://nbsphinx.readthedocs.io/
MIT License
451 stars 130 forks source link

Matplotlib Figures and stdout rendered as blank cells in html #652

Closed lee-t closed 2 years ago

lee-t commented 2 years ago

Unsure how to provide a minimal example for this so I'll just link to the respective files in my repo. I have a notebook that's being used to serve as documentation and it contains cells with pandas DataFrame, stdout from print()and matplotlib figures. I've configured sphinx to use nbsphinx as an extension, it parses the html. The resulting document renders pandas DF and cell outputs but nothing fromprint() nor any of the matplotlib figures fromplt.show() are rendered. For some reason, the images are saved in _images but the html page is built with the respective images linked to an empty container. None of the warnings from sphinx during make html tell me what is happening. Changing c.InlineBackend.figure_formats = {'png'} to svg does not resolve this issue and it does not matter if its specified in the conf.py, ipython_kernel_config.py, or the notebook itself (%config InlineBackend.figure_formats = ['png']).

I decided against making an issue with nbconvert because I've tried converting this into .rst and the figures do render but the pandas DF tables are poorly formatted, one of the reasons I'm using nbsphinx was because it automatically formats DF properly in html.

mgeier commented 2 years ago

This seems to be because of your custom CSS:

display(HTML("<style>.container { width:100% !important; }</style>"))

Can you try removing this?

lee-t commented 2 years ago

I have tried removing the line @mgeier mentioned, however the same issue seems to persist.

lee-t commented 2 years ago

I've addednbsphinx_execute = 'always' to conf.py, the plots and output now render in html. Seems that the saved output in the ipynb are not parsed unless the notebook is executed, not sure if this is intended behavior but between this and the custom CSS I think this issue is solved for my case at least. I don't see anyone else having this issue so I'm closing for now. Thank you Matthias.

mgeier commented 2 years ago

Good to know that it works now!

Seems that the saved output in the ipynb are not parsed unless the notebook is executed, not sure if this is intended behavior

Yes, this is intended. If the code cell outputs are stored in the notebook (like in your case), the default is to not execute it, see https://nbsphinx.readthedocs.io/en/0.8.9/executing-notebooks.html.

I normally remove the outputs before committing the notebooks to Git, then the notebooks are automatically executed.