Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
matplotlib.rcParams.update(params)

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
    
add comment

1 Answer 1

up vote 5 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
add comment

Your Answer

 
discard

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.