title: Reducing file sizes of PDFs created using matplotlib by changing font embedding
body: <p>I'm using matplotlib to produce PDF figures. However, even the simplest figures produce relatively large files, the MWE below produces a file of almost 1 MB. I've become aware that the large file size is due to matplotlib fully embedding all the used fonts. Since I'm going to produce quite a few plots and would like to reduce the file sizes, I'm wondering:</p>
  <p><strong>Main question:</strong></p>
  <p>Is there a way to get matplotlib to embed font <em>subsets</em> instead of the complete fonts?
  I would also be fine with not including the fonts at all.</p>
  <p><strong>Things considered so far:</strong></p>
  <ul>
  <li>A vector graphics editor can readily be used to export a PDF including font subsets (as well as not including fonts at all), but having to perform this step for every file (revision) appears unnecessarily tedious.</li>
  <li>Similarly, I've read about post-processing PDF-files (e.g. <a href="https://stackoverflow.com/a/10453202/12844571">using Ghostscript</a>), though the effort seems comparable.</li>
  <li>I tried setting 'pdf.fonttype'= 3, which does indeed produces considerably smaller files. However, I'd like to keep the text modifiable in vector graphics editors - which doesn't seem to work in this case (for example minus-signs will not be saved as text).</li>
  </ul>
  <p>Since it is easy, though labor-intensive, to produce files with embedded subsets using external software, is it somehow possible to achieve this directly in matplotlib? Any help would be greatly appreciated.</p>
  <p><strong>MWE</strong></p>
  <pre><code>import matplotlib.pyplot as plt #Setup
  import matplotlib as mpl
  mpl.rcParams['pdf.fonttype'] = 42
  mpl.rcParams['mathtext.fontset'] = 'dejavuserif'
  mpl.rc('font',family='Arial',size=12)
  
  fig,ax=plt.subplots(figsize=(2,2)) #Create a figure containing some text
  ax.semilogy(1,1,'s',label='Text\n$M_\mathrm{ath}$')
  ax.legend()
  fig.tight_layout()
  fig.savefig('test.pdf')
  </code></pre>
  <p>Environment: matplotlib 3.1.1</p>