Logarithmic y-axis bins in python

前端 未结 2 873
时光说笑
时光说笑 2020-11-30 06:32

I\'m trying to create a histogram of a data column and plot it logarithmically (y-axis) and I\'m not sure why the following code does not work:



        
相关标签:
2条回答
  • 2020-11-30 06:59

    np.logspace returns bins in [1-10], logarithmically spaced - in my case xx is a npvector >0 so the following code does the trick

    logbins=np.max(xx)*(np.logspace(0, 1, num=1000) - 1)/9
    hh,ee=np.histogram(xx, density=True, bins=logbins)
    
    0 讨论(0)
  • 2020-11-30 07:04

    try

    plt.yscale('log', nonposy='clip')
    

    http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.yscale

    The issue is with the bottom of bars being at y=0 and the default is to mask out in-valid points (log(0) -> undefined) when doing the log transformation (there was discussion of changing this, but I don't remember which way it went) so when it tries to draw the rectangles for you bar plot, the bottom edge is masked out -> no rectangles.

    0 讨论(0)
提交回复
热议问题