当我使用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/