只有xerrors的Matplotlib错误栏-错误的图例符号

时间:2018-10-26 04:00:31

标签: python matplotlib

当我这样做

import matplotlib.pyplot as plt
plt.errorbar(0., 0., xerr=1., capsize=3, capthick=3, label="wrong shape")
plt.legend()
plt.show()

我明白了

enter image description here

我认为这是不正确的,因为图例符号的线超出了端盖的左侧和右侧。如何解决这个问题,使图例符号只是|--|而不是-|--|-

1 个答案:

答案 0 :(得分:4)

Matplotlib在这种情况下可以正常工作。您必须使用关键字handlelength来指定行的长度。

import matplotlib.pyplot as plt
plt.errorbar(0., 0., xerr=1., capsize=3, capthick=3, label="wrong shape")
plt.legend(handlelength=1.)
plt.show()

enter image description here