我正在绘制几个带有 y 错误的数据点,并且我不希望图例中包含错误栏。
p1=ax.errorbar(x,y, yerr=[ydown,yup], color='blue', fmt='s', ecolor='blue')
p2=ax.errorbar(x1,y1, yerr=[y1down,y1up], color='black', fmt='.', ecolor='black')
ax.legend([p1,p2],['data1','data2'], loc='upper left', numpoints=1)
Run Code Online (Sandbox Code Playgroud)
我的问题与上一个问题类似: Matplotlib: Don't show errorbars in legend 但我还没有找到解决方案。谢谢。
您可以修改图例处理程序。请参阅matplotlib 的图例指南。调整您的示例,这可以是:
# get handles
handles, labels = ax.get_legend_handles_labels()
# remove the errorbars
handles = [h[0] for h in handles]
# use them in the legend
ax.legend(handles, labels, loc='upper left', numpoints=1)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4880 次 |
最近记录: |