title: How to get figure size and fontsize right for PDFs exported from matplotlib?
body: <p>I need to generate figures that fit into a particular width and use a particular font size, preferably without post-processing the pdf file.</p>
  
  <p>On my system, the default GUI backend is 'TkAgg' and the default font size is 12.0 as reported by the <code>get_fontsize()</code> method on a text object. When I generate a figure using</p>
  
  <pre><code>f = pyplot.figure(figsize=(2.0,2.0))
  f.text(0.5,0.5,'TEXT')
  pyplot.show()
  </code></pre>
  
  <p>and save as PDF, the figure size is too large. <code>pdfinfo</code> reports</p>
  
  <pre><code>Creator:        matplotlib 1.1.1rc, http://matplotlib.sf.net
  Producer:       matplotlib pdf backend
  CreationDate:   Sat May 25 10:52:02 2013
  Tagged:         no
  Pages:          1
  Encrypted:      no
  Page size:      196.2 x 153 pts
  File size:      9357 bytes
  Optimized:      no
  PDF version:    1.4
  </code></pre>
  
  <p>196.2 <a href="https://en.wikipedia.org/wiki/Point_%28typography%29#Current_DTP_point_system" rel="nofollow">pt</a> == 2.725 inch</p>
  
  <p>However, if I resize the figure to be 2 inch wide, the fontsize matches (visually) with 12pt LaTeX fonts.</p>
  
  <p>Contrarily, skipping the GUI produces a figure with the right dimensions, but fonts too large:</p>
  
  <pre><code>import matplotlib
  matplotlib.use('PDF')
  f = pyplot.figure(figsize=(2.0,2.0))
  f.text(0.5,0.5,'TEXT')
  f.savefig('test.pdf')
  
  Creator:        matplotlib 1.1.1rc, http://matplotlib.sf.net
  Producer:       matplotlib pdf backend
  CreationDate:   Sat May 25 10:50:42 2013
  Tagged:         no
  Pages:          1
  Encrypted:      no
  Page size:      144 x 144 pts
  File size:      9254 bytes
  Optimized:      no
  PDF version:    1.4
  </code></pre>
  
  <p>144 pt == 2.0 inch</p>
  
  <p>The Cairo backend produces the same result. Adding <code>f.set_size_inches((2,2))</code> doesn't change anything either.</p>
  
  <p>Is there a recipe to get font and figure sizes just right with matplotlib?</p>