基于另一个问题(make-custom-legend-in-matplotlib和force-errorbars-to-render-last-with-matplotlib),我说得对。
第二个错误不应该发生,我认为zorder选项可能有错误。如果我只为错误栏选择较大的数字,则错误栏的绘图将继续隐藏。所以我必须为for循环中的行的zorder设置一个负数。
解决问题的方法是:fig = plt.figure()
ax = fig.add_subplot(1,1,1)
for i in range(71):
ax.plot(LTbvall[i],UXbvall[i],'-',color ='#C0C0C0',label = 'Perfis COPEX',zorder = -32)
ax.plot(LTbvall[3],UXavg,'b*-', label = u'média')
ax.errorbar(LTbvall[3],UXavg, yerr = yerr,ecolor='b',zorder = 10)
#Get artists and labels for legend and chose which ones to display
handles, labels = ax.get_legend_handles_labels()
display = (0,71)
ax.set_xlabel('Tempo (LT)')
ax.set_xlim(0,24)
ax.set_ylabel('Ux (m/s)')
ax.set_title('Vento neutro meridional calculado pelo modelo NWM (BV)')
ax.legend([handle for i,handle in enumerate(handles) if i in display],
[label for i,label in enumerate(labels) if i in display], loc = 'best')
fig.savefig(path[9] + 'Uxbvall_LT_nwm')
plt.clf()
plt.gcf()
plt.close()
输出如下: