title: Matplotllib and Xelatex
body: <p>I tried to find the answer for my question for some time now but could not come up with something that works for me. My question is: How can you use Xelatex to compile text in Matplotlib?</p>
  
  <p>I know that there is this page:
  <a href="http://matplotlib.org/users/pgf.html" rel="nofollow">http://matplotlib.org/users/pgf.html</a></p>
  
  <p>However, I could not come up with something that would work. What I got up to now:</p>
  
  <pre><code>import matplotlib as mpl
  
  mpl.use("pgf")
  
  ## TeX preamble
  preamble = """
  \usepackage{fontspec}
  \setmainfont{Linux Libertine O}
  """
  
  params = {"text.usetex": True,
            'pgf.texsystem': 'xelatex',
            'pgf.preamble': preamble}
  
  mpl.rcParams.update(params)
  
  import matplotlib.pyplot as plt
  
  plt.plot([1, 2, 3])
  plt.xlabel(r'\textsc{Something in small caps}', fontsize=20)
  plt.ylabel(r'Normal text ...', fontsize=20)
  
  plt.savefig('test.pdf')
  </code></pre>
  
  <p>Running this code produces the following warning:
  /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_pgf.py:51: UserWarning: error getting fonts from fc-list
    warnings.warn('error getting fonts from fc-list', UserWarning)</p>
  
  <p>An output file is created but I don't the font is wrong (not Linux Libertine), even though I have the font installed and am able to use it with XeLaTex (I am able to write a pdf file using xelatex that is set in the Linux Libertine font). </p>
  
  <p>Any help would be really appreciated....</p>