Skip to content

Matplotlib

Peter Ebert edited this page Sep 22, 2022 · 1 revision

Matplotlib

Prepare plots for Illustrator

Problem: PDF files generated with matplotlib (observed in v3.5) contain text that is read as object/shape per letter by Adobe Illustrator. May also be a problem for other third-party tools.

Solution: set the following font type after importing matplotlib

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

Source: online 2022-09-22

Further explanation on font type 42: Wikipedia

Avoid transparent background (PDF or PNG output)

Problem: PDF or PNG plots have transparent background despite you setting transparent=False when calling savefig().

Solution: this weird problem can be solved by setting the following options

.savefig(... , transparent=None, facecolor="w")

Source: github issue 14339