如何在bokeh中以对数刻度显示直方图?

3
问题在标题中已经说明了。我正在尝试使用从bokeh.charts导入的直方图对象,但无法弄清如何以对数刻度显示它。在我的情况下,我需要x轴和y轴都以对数刻度显示。
2个回答

6

好的,看起来可以使用对数刻度。但是,我应该使用绘图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在另一个问题中提供的帮助!


5
请注意,@famagar提供的解决方法在最新版本的bokeh中不起作用(我刚试过0.12.14 --参见此问题)。
问题在于对数刻度无法正确处理零值
为了解决这个问题,需要将bottom参数设为非零值。例如,要获取与上面图像相同的结果,可以设置bottom=1p.quad(top=hist, bottom=1, left=edges[:-1], right=edges[1:], line_color=None)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接