如何在直方图的零线上添加一条轴线?

时间:2020-04-18 19:27:59

标签: python matplotlib

我有我的直方图,标有:

def hist_plt(data):
    counts, bins = data.clip(-.5, .5) |> np.histogram$(bins=100)
    plt.hist(bins[:-1], bins, weights=counts, alpha=0.3)

(python椰子语法)

它正在生成如下图: enter image description here

如何获得从零到顶部中间的一条漂亮的线?

作为一个额外的奖励问题,这些天是否有某种替代matplotlib的交互式图表库?

1 个答案:

答案 0 :(得分:0)

我认为您正在寻找的是vlines

def hist_plt(data):
    counts, bins = data.clip(-.5, .5) |> np.histogram$(bins=100)
    plt.hist(bins[:-1], bins, weights=counts, alpha=0.3)
    plt.vlines(x=0, ymin=0, ymax=1)

对于matplotlib的交互式替代方法,也许尝试bokehplotly