[英]Coloring a string using latex in matplotlib
我正在嘗試使用 matplotlib 中的乳膠並使用以下代碼為字符串着色,請參見此處:
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
有誰知道我應該向代碼添加/更新什么以消除錯誤,以便代碼按預期完美運行?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.