2017-02-23 61 views
0

我想從matplotlib轉移到散景。但是,我發現一些令人討厭的功能。最後一次遇到的情況是,需要花費幾分鐘才能製作大約150萬條記錄的直方圖 - Matplotlib只需要幾分之一秒的時間。這是正常的嗎?如果是這樣,原因是什麼?散焦圖表中的直方圖需要一個looong時間

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) 

回答

2

我不知道你的情況下可能會發生什麼。沒有數據文件,就不可能嘗試重現或調試。但是在任何情況下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) 

enter image description here

正如你可以看到,發生(在我的筆記本電腦)〜半秒爲1000萬點的直方圖,包括生成合成數據和裝箱。

+0

不幸的是,我無法分享原始數據集。它不回答我的文字問題,但是在這裏回答了底層問題:使用繪圖API繪製直方圖的解決方法是什麼?我將重申這個問題。非常感謝! - 我只希望我早幾小時知道這一點:( – famargar