问题
I'm trying to get the gamma symbol to be italicised in a plot label but can't figure out how to do it?
I thought this should work (but doesn't)
plt.xlabel(r'$\mathit{\Gamma}$$^{*}$')
I should add I am using the Helvetica font, so don't want to switch into tex mode, e.g. this doesn't work for me:
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = "sans-serif"
plt.rcParams['font.sans-serif'] = "Helvetica"
plt.rcParams['text.usetex'] = True
plt.plot(range(5), range(5))
plt.title('$\Gamma + \mathit{\Gamma}$', fontsize=40)
plt.show()
thanks,
Martin
回答1:
Write the text between '$$' that forces the text to be interpreted.
import matplotlib.pyplot as plt
plt.plot(range(5), range(5))
plt.title('$\it{text you want to show in italics}$')
plt.show()
回答2:
You should set usetex = True
. See here.
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rc('text', usetex = True)
plt.plot(range(5), range(5))
plt.title('$\Gamma + \mathit{\Gamma}$', fontsize=40)
plt.show()
Output:
回答3:
One solution I've found:
import matplotlib
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = "sans-serif"
plt.rcParams['font.sans-serif'] = "Helvetica"
plt.rcParams['text.usetex'] = False
plt.plot(range(5), range(5))
plt.title(u'${\u0413}$', fontsize=20)
plt.show()
来源:https://stackoverflow.com/questions/32470137/italic-symbols-in-matplotlib