【问题标题】:How to show a histogram in log scale with bokeh?如何使用散景显示对数刻度的直方图?
【发布时间】:2017-02-13 16:25:26
【问题描述】:

问题都在标题中。我正在尝试使用从 bokeh.charts 导入的直方图对象,但无法弄清楚如何以对数比例显示它。在我的特殊情况下,我需要 x 轴和 y 轴都以对数刻度显示。

【问题讨论】:

    标签: histogram bokeh


    【解决方案1】:

    好吧,似乎可以有对数刻度。但是,我应该使用绘图 API,而不是使用图表 API:

    import numpy as np
    from bokeh.plotting import figure, show, output_notebook
    
    output_notebook()
    
    # generate random data from a powerlaw
    measured = 1/np.random.power(2.5, 100000)
    
    hist, edges = np.histogram(measured, bins=50)
    
    p = figure(title="Power law (a=2.5)", x_axis_type="log", y_axis_type='log')
    p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color=None)
    
    show(p)
    

    感谢 bigreddot 对另一个问题的帮助!

    【讨论】:

      【解决方案2】:

      请注意,@famagar 的上述解决方案不适用于最新版本的散景(刚刚尝试使用 0.12.14 -- 请参阅 this issue)。

      问题在于日志缩放cannot properly handle zeros

      要解决这个问题,必须将bottom 参数设置为某个非零值。 比如要得到和上图一样的结果bottom=1

      p.quad(top=hist, bottom=1, left=edges[:-1], right=edges[1:], line_color=None)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-11
        • 2019-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-16
        • 2011-05-08
        • 2021-04-16
        相关资源
        最近更新 更多