3

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. ie if I click on the title in Illustrator (or your editor of choice), the entire title is a field of its own.

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.

Joe B
  • 912
  • 2
  • 15
  • 36
  • Does this answer your question? [Cannot edit text in chart exported by Matplotlib and opened in Illustrator](https://stackoverflow.com/questions/5956182/cannot-edit-text-in-chart-exported-by-matplotlib-and-opened-in-illustrator) – My Work Oct 13 '22 at 10:39

2 Answers2

8

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.

Helmer
  • 286
  • 2
  • 4
6

You might set the svg fonttype to 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")
  2. Open the pdf in Inkscape,
    i.e. File/Import... then choose the enter image description here option.
  3. Now you can edit the text in Inkscape.
  4. (optionally) export the figure from inkscape (e.g. as svg file) to later import it in any other program.
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712