【问题标题】:add a fill_between to the legend in python在 python 的图例中添加一个 fill_between
【发布时间】:2016-02-26 13:40:38
【问题描述】:

我正在尝试将我的 fill_between 添加到图例中,但它不起作用? 为什么它与其他地块不同?这是我现在的图表:

plt.scatter(stageheight,discharge,color='b',label='measured data')
plt.plot(stageheight_hecras,discharge_hecras,'y^',label='modeled with HEC-RAS')
plt.plot(stageheight_masked,discharge_predicted,'r-',label='regression line measured data')
plt.plot(stageheight_hecras,discharge_predicted_hecras,'g-',label='regression line HEC-RAS')
plt.plot(stageheight_masked,upper,'r--',label='15% error measured data')
plt.plot(stageheight_masked,lower,'r--')
plt.plot(stageheight_hecras,upper_hecras,'g--',label='30% error HEC-RAS')
plt.plot(stageheight_hecras,lower_hecras,'g--')
plt.fill_between(stageheight_masked,upper,lower,facecolor='red',edgecolor='red',alpha=0.5,label='test')
plt.fill_between(stageheight_hecras,upper_hecras,lower_hecras,facecolor='green',alpha=0.5)
plt.axhline(y=0.6,xmin=0,xmax=1,color='black',linewidth = 4.0,label='measuring  range')
plt.text(0.02,0.7,'measured rating curve $Q = 1.37H^2 + 0.34H - 0.007$\nmodeled ratign curve $Q = 1.14H^2 - 0.51H + 0.07$',bbox=dict(facecolor='none',edgecolor='black',boxstyle='square'))
plt.title('Rating curve Catsop')
plt.ylabel('discharge$[m^3/s]$')
plt.ylim(0,2.5)
plt.xlim(0,1.2)
plt.xlabel('stageheight$[m]$')
plt.legend(loc='upper left', title='Legend')
plt.grid(True)
plt.show()

【问题讨论】:

    标签: python matplotlib legend


    【解决方案1】:

    您使用的是什么版本的matplotlib?

    如果您升级到v1.5.0 或更高版本,这应该可以工作。更多详情请看这里:https://github.com/matplotlib/matplotlib/pull/3303#event-182205203

    【讨论】:

    • 在哪里可以查看我使用的版本?
    • import matplotlib; matplotlib.__version__ : '1.5.1'
    • 我有1.3.1版本,怎么下载1.5.1
    • 这取决于你在什么系统上,你如何安装 python 和你当前的 matplotlib 等等
    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 2013-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多