在matplotlib上绘制数据时,我使用errorbar放置散点图并绘制绘制线性拟合结果。我将错误栏输出存储在我向fig.ax.legend()
提供的数组中,以告诉它在图例中放置什么(我遵循matplotlib约定)。有没有办法告诉它在同一个图例行中添加拟合线?
答案 0 :(得分:2)
在matplotlib中至少v1.2.1,你可以add a tuple of lines that should be overlayed for the legend entry:
from pylab import *
fig = figure(1)
fig.clear()
x = linspace(0,2*pi,100)
y = sin(x)
yerr = y*.1
e = errorbar(x,y,yerr=yerr,label='data')
l, = plot(x,y,lw=3)
legend([(e,l)],['data & fit'])