title: How to set Matplotlib to render greek letters in sans-serif font
body: <p>I am generating some plots using Python (2.7) and Matplotlib (1.4.3), and would like <strong>all</strong> of the text in my plots to be in a sans-serif font. The best I have been able to achieve, using external LaTeX and the <em>sfmath</em> package, fails to set greek letters in sans-serif. This is demonstrated in the following MWE:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib import rc
  
  rc('text', usetex=True)
  rc('text.latex', preamble=r'\usepackage{sfmath}')
  
  fig, ax = plt.subplots()
  ax.plot([0,1,2], [2,5,9]) #arbitrary data
  ax.set_xlabel(r'$x$ (m)', fontsize=16)
  ax.set_ylabel(r'$y = \alpha(x)x^2 - 2\mu$', fontsize=16)
  ax.tick_params(axis='both', which='major', labelsize=16, pad=8)
  fig.tight_layout()
  fig.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/PwSsl.png" rel="nofollow noreferrer">[Output of above code (.png)]</a></p>
  
  <p>I am happy with the example axis labels except for the α and the μ which have been rendered in what looks like the default LaTeX serif font.</p>
  
  <p>Some other answers to questions I have looked at, involving changing various rc settings, which do not solve my problem:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/2537868/sans-serif-math-with-latex-in-matplotlib/">Sans-serif math with latex in matplotlib</a></li>
  <li><a href="https://stackoverflow.com/questions/22348756/upright-mu-in-plot-label-retaining-original-tick-fonts">Upright mu in plot label: retaining original tick fonts</a></li>
  <li><a href="https://stackoverflow.com/questions/13338550/typing-greek-letters-etc-in-python-plots">Typing Greek letters etc. in Python Plots</a></li>
  </ul>
  
  <p>The only example I have seen which seems to do what I want is <a href="http://fraserlab.com/2014/08/20/Figures-with-Python/" rel="nofollow noreferrer">here</a> (compare the first and last figures) but this requires modifying the matplotlibrc file. This is not suitable for my purposes; and in any case, I would be surprised if it were not possible to simply set it in the code as required.</p>
  
  <p><strong>(1) How can I modify the above code so that greek letters are displayed in the same sans-serif font as the rest of the text in the plot?*</strong></p>
  
  <p><strong>(2) Is it possible to do all of this using Matplotlib's built-in mathtext rather than relying an external LaTeX installation?</strong></p>
  
  <p>Many thanks in advance for any suggestions.</p>