diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index c7c34606525..96449a11ff5 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -3,6 +3,7 @@ ## In this release - ([#13051](https://github.com/quarto-dev/quarto-cli/issues/13051)): Fixed support for captioned Markdown table inside Div syntax for crossref. This is special handling, but this could be output by function like `knitr::kable()` with old option support. +- ([#12753](https://github.com/quarto-dev/quarto-cli/issues/12753)): Support change in IPython 9+ and import `set_matplotlib_formats` from `matplotlib_inline.backend_inline` in the internal `setup.py` script used to initialize rendering with Jupyter engine. ## In previous releases diff --git a/src/resources/jupyter/lang/python/setup.py b/src/resources/jupyter/lang/python/setup.py index 2206217f8f7..279cd5b2c00 100644 --- a/src/resources/jupyter/lang/python/setup.py +++ b/src/resources/jupyter/lang/python/setup.py @@ -22,7 +22,14 @@ plt.rcParams['figure.figsize'] = (fig_width, fig_height) plt.rcParams['figure.dpi'] = fig_dpi plt.rcParams['savefig.dpi'] = "figure" - from IPython.display import set_matplotlib_formats + + # IPython 7.14 deprecated set_matplotlib_formats from IPython + try: + from matplotlib_inline.backend_inline import set_matplotlib_formats + except ImportError: + # Fall back to deprecated location for older IPython versions + from IPython.display import set_matplotlib_formats + set_matplotlib_formats(fig_format) except Exception: pass diff --git a/tests/docs/smoke-all/jupyter/fig-format/matplotlib-svg.qmd b/tests/docs/smoke-all/jupyter/fig-format/matplotlib-svg.qmd new file mode 100644 index 00000000000..e79395b6cb7 --- /dev/null +++ b/tests/docs/smoke-all/jupyter/fig-format/matplotlib-svg.qmd @@ -0,0 +1,28 @@ +--- +title: Get SVG from matplotlib +format: + html: + fig-format: svg +_quarto: + tests: + html: + ensureHtmlElements: + - ['figure.figure img[src$=".svg"]'] + - ['figure.figure img[src$=".png"]'] +--- + +```{python} +import matplotlib.pyplot as plt +import numpy as np + +fig, ax = plt.subplots() + +x = np.linspace(0, 4 * np.pi, 100) +y1 = np.sin(x) +y2 = np.cos(x) + +ax.set_title("Sine and Cosine") +ax.plot(x, y1) +ax.plot(x, y2) +ax.legend(["Sine", "Cosine"]) +```