svg - 将matplotlib图形输出到SVG,文本作为文本,而不是曲线

标签 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" />

最佳答案

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

这将转换为以下代码,既不嵌入字体也不将文本呈现为路径:
import matplotlib.pyplot as plt
plt.rcParams['svg.fonttype'] = 'none'

关于svg - 将matplotlib图形输出到SVG,文本作为文本,而不是曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34387893/

相关文章:

python - Matplotlib 忽略时区

python - 创建子图而不是单独的图

javascript - 如何在我的 AngularJS 中获取此 D3.js HTML 元素以便我可以对其进行操作?

javascript - 如何让 HTML 中嵌入的 SVG 的 onclick 事件显示在 HTML 中?

html - 如何将一个 HTML 文件添加到另一个 HTML 文件的正文中?

javascript - ReactJS - SVG - 交互式时间线

css - Tweenlite 将转换添加到样式而不是自定义属性

python - 如何在 Pyplot 中获得平滑的平均曲线

python - 如何将样本的 x 位置与 matplotlib.pyplot 中的表列对齐?

numpy - 缺少值的pcolormesh?