【发布时间】:2017-02-13 16:25:26
【问题描述】:
问题都在标题中。我正在尝试使用从 bokeh.charts 导入的直方图对象,但无法弄清楚如何以对数比例显示它。在我的特殊情况下,我需要 x 轴和 y 轴都以对数刻度显示。
【问题讨论】:
问题都在标题中。我正在尝试使用从 bokeh.charts 导入的直方图对象,但无法弄清楚如何以对数比例显示它。在我的特殊情况下,我需要 x 轴和 y 轴都以对数刻度显示。
【问题讨论】:
好吧,似乎可以有对数刻度。但是,我应该使用绘图 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 对另一个问题的帮助!
【讨论】:
请注意,@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)
【讨论】: