Matplotlib - Stepped histogram with already binned data

前端 未结 4 1664
温柔的废话
温柔的废话 2020-12-15 06:13

I am trying to get a histogram with already binned data. I have been trying to use bar() for this, but I can\'t seem to figure out how to make it a stepped hist

4条回答
  •  粉色の甜心
    2020-12-15 06:55

    You could cheat, by offsetting your data and using plot instead:

    from matplotlib import pyplot
    import numpy as np
    
    #sample data:
    x = np.arange(30)
    y = np.cumsum(np.arange(30))
    #offset the x for horizontal, repeat the y for vertical:
    x = np.ravel(zip(x,x+1))
    y = np.ravel(zip(y,y))
    
    pyplot.plot(x,y)
    pyplot.savefig('plt.png')
    

    the plot:

    enter image description here

提交回复
热议问题