3

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.

Community
  • 1
  • 1
Bogdan Janiszewski
  • 2,743
  • 3
  • 20
  • 25

1 Answers1

5

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".

ev-br
  • 24,968
  • 9
  • 65
  • 78
  • Thanks! This makes much more sense. – Bogdan Janiszewski Nov 07 '14 at 22:24
  • This doesn't answer the question. This solution basically forces the user to manually make all text appearing in a plot the same by applying a TeX font. The REAL solution should involve changing the default font used by TeX to match the one default font used by matplotlib. – Will.Evo May 25 '16 at 21:41