I am trying to export my figure as a PDF. I run into the problem that when I want to edit it (in this case by Graphic on macOS) that the font appears not to be found by the editor. My question is, how do I solve this? Can I 'install' the fonts used by matplotlib?
import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot([0,1], [0,1]) plt.savefig('test.pdf')
This PDF looks fine in Preview:
But in the editor, it gives gibberish:
(see this answer).
What works is to install all matplotlib's fonts. I have followed this answer to find all matplotlib's ttfs, and installed them. This works and solves the problem.
But... This does solve the issues when LaTeX is enabled, by
import matplotlib matplotlib.rcParams['text.usetex'] = True
How do I install the fonts that matplotlib uses now?
A solution here is to export as SVG. However, for some reason this takes ages on my system (see this bug).
What pdf editor are you using? I don't know how to check whether an attempt to solve this is working... but I always use this code to save images in pdf or png:
plt.savefig('test.pdf', edgecolor='none', bbox_inches="tight")
I have found a workaround. This is to convert all fonts to outlines before editing. One way to do this is with GhostScript with the option
-dNoOutputFonts, as described in this answer:
gs -o file-with-outlines.pdf -dNoOutputFonts -sDEVICE=pdfwrite file.pdf