输出matplotlib图到SVG,文本为文本,而不是曲线

Bra*_*ram 22 svg matplotlib

当我使用matplotlib.pyplot.savefig("test.svg", format="svg")将图形导出为SVG时,生成的SVG文件非常庞大.

这是因为我的图中有很多文本注释,每个文本最终都是SVG中的路径.

我希望我的文本最终成为SVG中的文本字符串,而不是路径.如果文本字符串以这种方式导出,那么解释输出也变得太难了.

有没有办法强制matplotlib输出文本作为文本,而不是曲线?

目前,我在SVG文件中看到了这些代码片段:

<path d=" M9.8125 72.9062 L55.9062 72.9062 L55.9062 64.5938 L19.6719
64.5938 L19.6719 43.0156 L54.3906 43.0156 L54.3906 34.7188 L19.6719
34.7188 L19.6719 8.29688 L56.7812 8.29688 L56.7812 0 L9.8125 0 z "
id="DejaVuSans-45" />
Run Code Online (Sandbox Code Playgroud)

zli*_*liw 27

Matplotlibs SVG文本渲染可以在matplotlibrc或代码中配置.来自http://matplotlib.org/users/customizing.html:

#svg.fonttype : 'path'         # How to handle SVG fonts:
#    'none': Assume fonts are installed on the machine where the SVG will be viewed.
#    'path': Embed characters as paths -- supported by most SVG renderers
#    'svgfont': Embed characters as SVG fonts -- supported only by Chrome,
#               Opera and Safari
Run Code Online (Sandbox Code Playgroud)

这转换为以下代码既不嵌入字体也不将文本呈现为路径:

import matplotlib.pyplot as plt
plt.rcParams['svg.fonttype'] = 'none'
Run Code Online (Sandbox Code Playgroud)

  • 我不明白为什么这不是默认值 (4认同)
  • @ShrirajHegde 当选择默认值时我不在场,但我怀疑权衡是 svg 大小与 svg 不渲染文本。 (3认同)