I recently found I could make all my matplotlib figures with SVG by default in my jupyterlab notebooks with
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_formats = ['svg']
However, if I refresh the page, the figures disappear, leaving behind
<Figure size 864x576 with 1 Axes>
This effect does not occur without changing the inline backend. My plotly figures also still show up after a refresh. I would prefer not to have to re-run the cells. Looking at the actual ipynb file, the SVG is right there in the actual file. How can I get this figure to show without re-running the cell?
The behaviour looks in line with the security model of Jupyter.
- Untrusted HTML is always sanitized
- Untrusted Javascript is never executed
- HTML and Javascript in Markdown cells are never trusted
- Outputs generated by the user are trusted
- Any other HTML or Javascript (in Markdown cells, output generated by others) is never trusted
- The central question of trust is “Did the current user do this?”
Because SVG can have <script>
tags, there's an attack surface. Hence, you have two options to display the SVG:
jupyter trust /path/to/notebook.ipynb
.Notes:
image/png
version in the output of the cell. It's displayed when the notebook is loaded. But the loaded (not reran) cell also has interactivity. Not sure how that exemption works.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With