散景图表中的直方图需要很长时间

Histogram in Bokeh charts takes a looong time

我正在尝试从 matplotlib 转移到散景。但是,我发现了一些烦人的功能。我最后一次遇到的情况是,制作一个包含大约 150 万个条目的直方图需要几分钟——如果使用 Matplotlib,则只需几分之一秒。那是正常的吗?如果是这样,原因是什么?

from bokeh.charts import Histogram, output_file, show
import pandas as pd
output_notebook()
jd1 = pd.read_csv("somefile.csv")
p = Histogram(jd1['QTY'], bins=50)
show(p)

我不确定在您的情况下 Histogram 可能会发生什么。没有数据文件,就不可能尝试重现或调试。但无论如何 bokeh.charts 目前并没有真正的维护者,所以我实际上只建议使用 bokeh.plotting 来创建你的 historgam。 bokeh.plotting API 是稳定的(现在已经好几年了)并且有广泛的文档记录。就是多了几行代码,但不多:

import numpy as np
from bokeh.plotting import figure, show, output_notebook

output_notebook()

# synthesize example data
measured = np.random.normal(0, 0.5, 1000)

hist, edges = np.histogram(measured, density=True, bins=50)

p = figure(title="Normal Distribution (μ=0, σ=0.5)")
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color=None)

show(p)

如您所见,(在我的笔记本电脑上)1000 万点直方图需要大约半秒的时间,包括生成合成数据并将其合并。