# Changing font style for latex rendering using PyPlot

#1

Hi all,

I am trying to make plots, using PyPlot, that have latex equations. Does anyone know how to change the font of the default latex render in PyPlot ? Right now I am using the following:

PyPlot.matplotlib[:rc]("text", usetex=false) # allow tex rendering
rc("font", family="sans-serif", weight="normal", size="18")
rc("axes", labelsize="18")


If I write for example:

xlabel(L"Linear")


I get “Linear” where I would like to have just “Linear”

The same is valid if I write:

xlabel(L"2x")

then I get “2x” where I would like to have “2x”.

thank you

#2

The L"Linear" form makes PyPlot treat the whole string as a math expression (as if surrounded by dollar signs in \LaTeX). Either use "Linear" or (to embed normal text in a math expression) L"\mathrm{Linear}".

This is not iron-clad: if you specify rc("font",style="italic"), you may not be able to get away from italics at all.

The reference is http://matplotlib.org/users/mathtext.html

#3

If you don’t want an equation, you just shouldn’t use L"…" at all. Just use an ordinary string.

All L"…" does is allow you to enter equations without having to insert tons of backslash escapes, and to allow you to optionally omit the .... There is no reason to use it if you don’t want an equation.

#4

Well - except to match fonts. In this case just use L"\text{blah}" or possibly L"{\rm blah}" - I didn’t test this but something along those lines will work

#5

thank you, this answer solved my problem. What I was looking for was something like: L"\mathsf{<b> / <b_0>}" for example