简体   繁体   English

如何将matplotlib图形导出为带有可编辑文本字段的矢量图形?

[英]How can I export a matplotlib figure as a vector graphic with editable text fields?

I am trying to export multiple plots for editing in Adobe Illustrator and I am trying to make the title, the axis labels, and the bar chart labels as individual text fields. 我正在尝试导出多个绘图以便在Adobe Illustrator中进行编辑,我试图将标题,轴标签和条形图标签作为单独的文本字段。 ie if I click on the title in Illustrator (or your editor of choice), the entire title is a field of its own. 即如果我在Illustrator(或您选择的编辑器)中单击标题,则整个标题都是它自己的字段。

Here's how I am exporting as vector graphics without text fields: 这是我如何导出为没有文本字段的矢量图形:

plt.bar(x_data, y_data)
plt.title('Fancy Title')
plt.xlabel('Informative X label')
plt.ylabel('Felicitous Y label')
plt.draw()
fig.savefig(savepath, bbox_inches='tight', format='svg')
plt.show()

This outputs a nice vector graphic, but I can't edit the text as fields. 这会输出一个漂亮的矢量图形,但我无法将文本编辑为字段。 I can run it through a text conversion software, but that moves text ever so slightly and makes everything appear off and leaves font detection up to the software. 我可以通过文本转换软件来运行它,但是它会轻微地移动文本并使所有内容都显示为关闭并使字体检测到软件。

Try these lines: 试试这些:

import matplotlib as mpl
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42

In my experience, the default fonttype is not editable, but this one is. 根据我的经验,默认的fonttype是不可编辑的,但是这个是。

You might set the svg fonttype to none: 您可以将svg fonttype设置为none:

import matplotlib.pyplot as plt
plt.rcParams['svg.fonttype'] = 'none'

The following also works: 以下也有效:

  1. Save the figure as pdf, plt.savefig("filename.pdf") 将图形保存为pdf, plt.savefig("filename.pdf")
  2. Open the pdf in Inkscape , Inkscape中打开pdf,
    ie File/Import... then choose the 即文件/导入...然后选择 在此输入图像描述 option. 选项。
  3. Now you can edit the text in Inkscape. 现在,您可以编辑Inkscape中的文本。
  4. (optionally) export the figure from inkscape (eg as svg file) to later import it in any other program. (可选)从inkscape导出图形(例如,作为svg文件)以便稍后在任何其他程序中导入它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM