[英]Labelling a coloured area under a graph
我希望能夠在圖例下的彩色區域的圖例框中顯示標簽。 着色區域在13 <x <17到22 <x <29之間
我在用:
for i in data.findOne()
a = [element['total'] for element in i['counts']]
P.plot(a, label="curve 1", color='green')
where = np.zeros(len(a),dtype=bool)
where[13:17] = True
where[22:29] = True
P.fill_between(np.arange(len(a)),a,where=where,color='green', alpha='0.5')
P.legend()
P.show()
我在哪里可以插入命令來顯示它的圖例? 我希望陰影區域的圖例與曲線的圖例位於同一個圖例框中。
謝謝!
這就是它的樣子:
當前標簽機制不支持由fill_between返回的PolyCollection。 你可以做的是創建一個任意的補丁作為代理藝術家,並將其添加為占位符,例如:
from matplotlib.patches import Rectangle
import numpy as np
import pylab as P
xs = np.arange(0,10,0.1)
line1 = P.plot(xs,np.sin(xs),"r-", label="lower limit")[0]
line2 = P.plot(xs,np.sin(xs-1)+3,"b-", label="upper limit")[0]
P.fill_between(xs,np.sin(xs), np.sin(xs-1)+3,color='green', alpha=0.5, label="test")
rect = Rectangle((0, 0), 1, 1, fc="g", alpha=0.5)
P.legend([line1, line2, rect], ["lower limit", "upper limit", "green area"])
P.show()
給我們:
供參考,請參閱此內容
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.