[英]Latex colors not rendered in matplotlib text
我的繪圖腳本中似乎忽略了 Tex 的\\textcolor
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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.