Legend not showing up in Matplotlib stacked area plot

后端 未结 4 2044
借酒劲吻你
借酒劲吻你 2020-12-13 14:59

I am creating a stacked line/area plot using plt.fill_between() method of the pyplot, and after trying so many things I am still not able to figure why it is not displaying

4条回答
  •  长情又很酷
    2020-12-13 15:15

    gcalmettes's answer was a helpful start, but I wanted my legend to pick up the colors that the stackplot had automatically assigned. Here's how I did it:

    polys = pyplot.stackplot(x, y)
    legendProxies = []
    for poly in polys:
        legendProxies.append(pyplot.Rectangle((0, 0), 1, 1, fc=poly.get_facecolor()[0]))
    

提交回复
热议问题