乳胶颜色未在matplotlib文本中呈现

问题描述 投票:1回答:1

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()

它没有给我一个红色文字,它产生:

enter image description here

我错过了什么吗?

python matplotlib latex
1个回答
1
投票

这里有更详细的解释: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()
© www.soinside.com 2019 - 2024. All rights reserved.