python Bokeh直方图:调整x比例和图表样式
我有一个使用Bokeh的python柱状图:python Bokeh直方图:调整x比例和图表样式,python,plot,bokeh,Python,Plot,Bokeh,我有一个使用Bokeh的python柱状图: 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 Dist
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刻度更改为log10
-我想要一条平滑的线(像分布图)而不是条线
有人知道如何进行这些调整吗?这可以通过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)