gpt4 book ai didi

python - 将绘图中的线条与 matplotlib 图例中错误栏中的标记组合起来

转载 作者:行者123 更新时间:2023-12-01 05:42:21 25 4
gpt4 key购买 nike

在matplotlib上绘制数据时,我使用误差条来放置散点标记并绘制线性拟合结果。我将 errorbar 输出存储在一个数组中,并提供给 fig.ax.legend() 来告诉它在图例中放置什么(我遵循 matplotlib 约定)。有没有办法告诉它在同一图例行中添加拟合线?

最佳答案

在 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'])

combined line and errorbar legend

关于python - 将绘图中的线条与 matplotlib 图例中错误栏中的标记组合起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17212641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com