【发布时间】:2013-06-20 11:38:10
【问题描述】:
在 matplotlib 上绘制数据时,我使用 errorbar 放置散点标记并使用 plot 绘制线性拟合结果。我将错误栏输出存储在一个数组中,我提供给fig.ax.legend() 以告诉它在图例中放置什么(我遵循 matplotlib 约定)。有没有办法告诉它在同一图例行中添加拟合线?
【问题讨论】:
标签: python matplotlib legend
在 matplotlib 上绘制数据时,我使用 errorbar 放置散点标记并使用 plot 绘制线性拟合结果。我将错误栏输出存储在一个数组中,我提供给fig.ax.legend() 以告诉它在图例中放置什么(我遵循 matplotlib 约定)。有没有办法告诉它在同一图例行中添加拟合线?
【问题讨论】:
标签: python matplotlib legend
在至少v1.2.1的matplotlib中,可以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'])
【讨论】:
self.tolegs == []、self.tolegs.append(e,p))。当我尝试放置图例时出现错误:AttributeError: 'NoneType' object has no attribute 'create_artists'
self.tolegs?
self.tolegs.append 提供两个参数是一个错字?当我给它多个参数时,我在 python 中得到一个错误。