How to make matplotlib/pandas bar chart look like hist chart?

后端 未结 2 842
Happy的楠姐
Happy的楠姐 2020-12-18 08:10

Plotting Differences between bar and hist

Given some data in a pandas.Series , rv, there is a difference between

2条回答
  •  感动是毒
    2020-12-18 08:45

    Another, simpler solution is to create fake samples that reproduce the same histogram and then simply use hist().

    I.e., after retrieving bins and counts from stored data, do

    fake = np.array([])
    for i in range(len(counts)):
        a, b = bins[i], bins[i+1]
        sample = a + (b-a)*np.random.rand(counts[i])
        fake = np.append(fake, sample)
    
    plt.hist(fake, bins=bins)
    

提交回复
热议问题