python - 乳胶颜色未在 matplotlib 文本中呈现
问题描述
\textcolor
在我的绘图脚本中似乎忽略了Tex
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()
推荐阅读
- angularjs - 如何在过滤器中添加条件?
- django - 3rd 方私有 API 密钥从客户端的用户那里获取并存储在数据库中 - 如何使其安全?
- angular7 - 为什么“angular-tag-cloud-module”的颜色不起作用?
- java - Android Studio 中的蓝牙耳机按钮触发,SDK 级别 Min API 15 和 Max API 28
- linux - 如何在没有 .sh 扩展名的情况下运行 bash 脚本?
- angular - 如何在 ng-bootstrap 中动态添加 typeahead?角度 7/8
- android - 如何在 Android AOSP 下构建/交叉编译现有的介子或 cmake 项目?
- c# - 获取 MS Teams 频道对话 ID
- flutter - 如何使用颤振创建非对称表
- php - 如果当前状态 X,则阻止状态更新