supg jupyter笔记本内联图

Fab*_*ost 21 svg matplotlib jupyter-notebook

默认情况下,jupyter笔记本内联图显示为png,例如:

import matplotlib.pyplot as plt
%matplotlib inline
plt.plot()
Run Code Online (Sandbox Code Playgroud)

你如何配置jupyter笔记本显示matplotlib内嵌图作为svg?

Fab*_*ost 44

%config InlineBackend.figure_formats = ['svg']诀窍.一个最小的例子是:

%config InlineBackend.figure_formats = ['svg']

import matplotlib.pyplot as plt
%matplotlib inline
plt.plot()
Run Code Online (Sandbox Code Playgroud)

  • 你知道使用`%matplotlib notebook`时是否有类似的修复方法?我似乎无法找到一种方法使图形显示为svg质量 (2认同)
  • @FabianRost `InlineBackend.figure_format` 在 IPython 2.0 上[已弃用](https://ipython.readthedocs.io/en/stable/whatsnew/version2.0.html?highlight=figure_formats#selecting-matplotlib-figure-formats)。 0,使用 [`set_matplotlib_formats`](https://ipython.readthedocs.io/en/stable/api/ generated/IPython.display.html#IPython.display.set_matplotlib_formats) 代替。 (2认同)
  • @Zoltan 感谢您的澄清!它写在我链接的变更日志中,所以我知道这一点,但我更喜欢少用魔法。此外,[`set_matplotlib_formats()`](https://ipython.readthedocs.io/en/stable/api/ generated/IPython.display.html#IPython.display.set_matplotlib_formats)可以设置图像格式和其他选项,例如质量同时。 (2认同)

nek*_*uuu 12

使用set_matplotlib_formats('svg').

import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
%matplotlib inline
set_matplotlib_formats('svg')
plt.plot()
Run Code Online (Sandbox Code Playgroud)

这也记录在%matplotlib magic的文档中.

注意:InlineBackend.figure_format弃用.

  • 看来这种形式现在也已被弃用。我得到: 自 IPython 7.23 起,`set_matplotlib_formats` 已被弃用,从 sys.path 中删除 cwd 后直接使用 `matplotlib_inline.backend_inline.set_matplotlib_formats()` 。 (2认同)

Shr*_*gde 12

set_matplotlib_formats()自 2021 年 5 月起已弃用。

DeprecationWarning:set_matplotlib_formats自 IPython 7.23 起已弃用,直接使用matplotlib_inline.backend_inline.set_matplotlib_formats() set_matplotlib_formats('svg')

目前的工作方式:

%matplotlib inline
import matplotlib_inline
matplotlib_inline.backend_inline.set_matplotlib_formats('svg')
Run Code Online (Sandbox Code Playgroud)