【发布时间】:2013-01-27 07:16:40
【问题描述】:
我有一些数据(有错误)要绘制在相当密集的显示中。我想在没有误差条的情况下绘制这些点(因为它太忙了),但要在图例中绘制一个有代表性的误差条(它以准确的大小显示误差条)。
这是我到目前为止所拥有的(不成功)。
import pylab as pl
p1, = pl.plot([1,2,3], label="test1")
p2, = pl.plot([3,2,1], label="test2")
errorbarsize = 1.65 # Need this to be properly scaled in the legend
# p3, = pl.plot([1], label='data', color="red") # works
# p3, = pl.scatter(1, 1, label='data', color="red")
# p3, = pl.errorbar(1, 1, yerr=errorbarsize, label='data', color="red")
l1 = pl.legend([p1], ["Label 1"], loc=1)
l2 = pl.legend([p2], ["Label 2"], loc=2) # this removes l1 from the axes.
l3 = pl.legend([p3], ["Label 3"], loc=3, numpoints=1)
gca().add_artist(l1) # add l1 as a separate artist to the axes
gca().add_artist(l2) # add l2 as a separate artist to the axes
另外,如果我可以将其绘制在单独的图例中,那将是最好的,但这可能要求太多。
【问题讨论】:
-
你看过
erroreverykwarg docerrorbar(..., errorevery=15)只会每15个数据点绘制一个误差线。 -
也许你也可以试试
fill_between(x,y-errorbarsize/2, y+errorbarsize/2,alpha=0.3)
标签: python matplotlib legend subplot