TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating many figures for my LaTeX document using matplotlib with 'text.usetex': True.

My full preamble looks like this:

rc('font', **{'family':'serif', 'serif':['Computer Modern Roman']})
params = {'backend': 'pdf',
          'axes.labelsize': 12,
          'text.fontsize': 12,
          'legend.fontsize': 12,
          'xtick.labelsize': 10,
          'ytick.labelsize': 10,
          'text.usetex': True,
          'figure.figsize': fig_size,
          'axes.unicode_minus': True}

In the plot I also use \texttt{}, which should match the formatting in the latex document. However it doesnt (compare legend and caption, both 12pt).

Matplotlib figure and caption. Typewriter text is rendered differently.

I assume I have to add something like 'family':'typewriter', 'typewriter':['Some font']. So my questions:

  • how can I find out which font and weight is used in the LaTeX document for \texttt
  • How to tell matplotlib to use the exact same font
share|improve this question
up vote 7 down vote accepted

Matplotlib apparently uses Courier as default, my LaTeX uses Computer Modern Typewriter.

I found some font specification examples here.

So changing the first line of my preamble to

rc('font', **{'family':'serif', 'serif':['Computer Modern Roman'], 
                                'monospace': ['Computer Modern Typewriter']})

renders the \texttt{} the same way LaTeX does.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.