Python 在图形下标记彩色区域

Python 在图形下标记彩色区域,python,graph,matplotlib,label,legend,Python,Graph,Matplotlib,Label,Legend,我希望能够在图例框中显示图形下彩色区域的标签。彩色区域介于13

我希望能够在图例框中显示图形下彩色区域的标签。彩色区域介于13 我正在使用:

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\u-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()
给了我们:


作为参考,请参见

如果我想给曲线下的两个不同区域上色,这是否可行?(参见上面的屏幕截图)当然-我不希望您需要为具有相同颜色的区域创建图例条目,是吗?我编辑了我的示例,以便更好地适应您更改的问题。