I am trying to get non-italic greek characters into my matplotlib titles and labels, for example μ. I have so far written greek characters as follows:
plt.title('$\mu$)
This would print an italic mu. Now hoping to get it to be non-italic, I have tried to do:
plt.title('$\mathrm{\mu}$')
Sadly this does not change it at all, even though using \mathrm does work for normal characters. For example plt.title('$\mathrm{test}$') correctly prints 'test' in a non-italic font.
Why is this behaviour different for greek characters, and how do I fix this? I have googled and found more questions on this problem, but I couldn't get a clear answer on why \mathrm does not work and how I can solve this.
Thanks in advance!
This is more of a TeX font issue rather than a Python issue. The best solution for you is to use change the latex rc config for matplotlib like below
import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['mathtext.default'] = 'regular'
Or in case you need italics in some parts just add \it before a text or a symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With