如何使用散景以对数刻度显示直方图?

fam*_*gar 1 histogram bokeh

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

fam*_*gar 5

好吧,似乎可以有对数刻度。但是,我应该使用绘图 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)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

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


小智 5

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

问题是对数刻度无法正确处理零

为了解决这个问题,必须将bottom参数设置为某个非零值。例如,要获得与上图相同的结果bottom=1

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