[英]latex-markdown labels on matplotlib
我有一個matplotlib
圖表,我想用乳膠降價注釋。
axs.annotate(s='$r_f = {:.2f}$'.format(r), xy=[2005, 7],
xycoords="data", fontsize=18)
這可以正常工作,但是我希望在下標中包含多個字母的乳膠代碼。 我需要$r_{fit}$
,但這使python的format方法的內部系統混亂。
c:\Users\Dean\Dropbox\Dean\Study\_Thesis\2. Paper\code\paper\charts.py in plot_prediction(x, y, data, future_x, future_y, future_data, death)
141 axs.scatter(x, data, label='Train Data', color=_palette[0])
142 r, p = pearsonr(y, data)
--> 143 axs.annotate(s=r'$r_{fit} = {:.2f}$'.format(r), xy=[2005, 7],
144 xycoords="data", fontsize=18)
145 # print p
KeyError: 'fit'
我嘗試過使用逃脫字符進行許多操作,但是沒有任何效果。
問題是格式/字符串而不是matplotlib,我得到了錯誤,
"$r_{fit} = {:.2f}$".format(10.)
KeyError Traceback (most recent call last)
<ipython-input-41-2d336f9a0477> in <module>()
----> 1 "$r_{fit} = {:.2f}$".format(10.)
KeyError: 'fit'
"$r_{{fit}} = {:.2f}$".format(r)
另一個簡單的解決方法是將下標和格式語句分開,
"$r_{fit}" + " = {:.2f}$".format(r)
它也可以按預期工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.