0

我希望能够在图例下方的彩色区域的图例框中显示一个标签。彩色区域介于 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()

我在哪里可以插入一个命令来显示它的图例?我希望阴影区域的图例与曲线图例位于同一个图例框中。

谢谢!

这是它的样子:

例子

4

1 回答 1

2

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()

给我们: 样本

供参考,请参阅

于 2013-01-10T12:16:42.960 回答