Bogdan Janiszewski
Bogdan Janiszewski

Reputation: 2873

Non-italicized Latex font in matplotlib

I have a matplotlib plot where on of the x-axis labels has math type in it that I used LaTeX to create. The problem is that the font is italicized and I need it to match the font of the previous text (non-italicized). The code looks as follows:

par2.set_xlabel("Flux ($neutrons/cm^2s)" , fontsize=26 , labelpad = 20)

I found another related (link) question where they suggested adding a \rm and tried the following from it:

plt.xlabel(r'Primary T$_{\rm eff}$')

So that my code would look like:

par2.set_xlabel("Flux ($\rmneutrons/cm^2s)" , fontsize=26 , labelpad = 20)

But all that does is add an 'm' in front of neutrons

How can I get the font non-italicized so that it matches everything else.

Upvotes: 3

Views: 5032

Answers (1)

ev-br
ev-br

Reputation: 26030

Try r"Flux, $\mathrm{neutrons} / \mathrm{cm}^2$".

By the way, this is nothing to do with matplotlib, this is a pure TeX issue. The only python-specific thing here is the need to use a raw string, r"notice the r before the quotation mark".

Upvotes: 6

Related Questions