2017-09-05 16 views
3

我使用背景虛化Python中的柱狀圖:蟒蛇背景虛化直方圖:調整X規模和圖表樣式

from bokeh.charts import Histogram 
from bokeh.sampledata.autompg import autompg as df 
#from bokeh.charts import defaults, vplot, hplot, show, output_file 

p = Histogram(df, values='hp', color='cyl', 
       title="HP Distribution (color grouped by CYL)", 
       legend='top_right') 
output_notebook() ## output inline 

show(p) 

我想調整如下: - X比例變更日誌10 - 取而代之的酒吧,我想要一條平滑線(如分佈圖)

有誰知道如何進行這些調整?

+0

看看這有助於:https://stackoverflow.com/questions/22729019 /-一個陣列分佈情節的 – Dalton

回答

3

這可以通過使用bokeh.plotting API來完成,使您可以更好地控制裝箱和平滑。下面是一個完整的例子(也繪製好措施直方圖):

from bokeh.io import output_file, show 
from bokeh.plotting import figure 
from bokeh.sampledata.autompg import autompg as df 

from numpy import histogram, linspace 
from scipy.stats.kde import gaussian_kde 

pdf = gaussian_kde(df.hp) 

x = linspace(0,250,200) 

p = figure(x_axis_type="log", plot_height=300) 
p.line(x, pdf(x)) 

# plot actual hist for comparison 
hist, edges = histogram(df.hp, density=True, bins=20) 
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], alpha=0.4) 

output_file("hist.html") 

show(p) 

隨着輸出:

enter image description here