我正在尝试在matplotlib中使用Latex并使用以下代码为字符串着色,请参见here:
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('ps')
from matplotlib import rc
rc('text',usetex=True)
rc('text.latex', preamble='\usepackage{color}')
plt.figure()
plt.ylabel(r'\textcolor{red}{Today} '+
r'\textcolor{green}{is} '+
r'\textcolor{blue}{cloudy.}')
但是在执行上述代码时,出现以下错误:
File "<ipython-input-38-6ffb8d156b19>", line 7
rc('text.latex', preamble='\usepackage{color}')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \uXXXX escape
有人知道我应该在代码中添加/更新什么以消除错误,以便代码按预期正常运行吗?