jupyter notebook 内联图为 svg

jupyter notebook inline plots as svg

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

import matplotlib.pyplot as plt
%matplotlib inline
plt.plot()

如何配置 jupyter 笔记本以将 matplotlib 内联图显示为 svg?

%config InlineBackend.figure_formats = ['svg'] 就可以了。一个最小的例子是:

%config InlineBackend.figure_formats = ['svg']

import matplotlib.pyplot as plt
%matplotlib inline
plt.plot()

使用set_matplotlib_formats('svg').

import matplotlib.pyplot as plt
from IPython.display import set_matplotlib_formats
%matplotlib inline
set_matplotlib_formats('svg')
plt.plot()

这也记录在 a document of %matplotlib magic 中。

注意:InlineBackend.figure_formatdeprecated