Tex的\textcolor
似乎在我的plottling脚本中被忽略了
import matplotlib as matplotlib
from matplotlib import pyplot as plt
matplotlib.rcParams.update({'text.usetex': True})
matplotlib.rc(
'text.latex', preamble=r"\usepackage{xcolor}")
fig, ax = plt.subplots()
ax.set_ylabel(r'\textcolor{red}{aaaaaaa}')
plt.show()
它没有给我一个红色文字,它产生:
我错过了什么吗?
这里有更详细的解释:https://matplotlib.org/users/usetex.html但似乎只有在将它导出到ps文件时才有效。对我来说,如果你将它保存为ps文件,它会以彩色工作,而同一文件内联不起作用。
这里有轻微的解决方法。
import matplotlib as matplotlib
from matplotlib import pyplot as plt
matplotlib.rcParams.update({'text.usetex': True})
matplotlib.rc('text.latex', preamble=r"\usepackage{xcolor}")
fig, ax = plt.subplots()
ax.set_ylabel(r"aaaaaaa", color='r')
#plt.savefig(r"foo.ps")
# you can include the above line if you're using your old code.
plt.show()