使用Bokeh绘制加权数据的直方图

3
如何使用bokeh为加权数据生成直方图?
在matplotlib中,可以执行以下操作:
from pylab import hist
x = randn(100); w = rand(100)
hist(x, weights=w)

如何在bokeh中完成同样的事情?
1个回答

0

基本上,你需要将权重传递给你的numpy直方图函数。

import numpy as np

from bokeh.layouts import gridplot
from bokeh.plotting import figure, show, output_file

p1 = figure(title="Normal Distribution (μ=50, σ=20) and normal weights",tools="save",
        background_fill_color="#E8DDCB")

measured = np.random.normal(50, 20, 1000)

myweights = np.random.normal(0, 1, 1000)
hist, edges = np.histogram(measured, density=True, bins=10,weights=myweights)

x = np.linspace(-2, 2, 1000)
p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
    fill_color="#036564", line_color="#033649")
p1.legend.location = "top_left"
p1.xaxis.axis_label = 'x'
p1.yaxis.axis_label = 'Pr(x)'

show(p1)

基本上,你只是复制了Bokeh的示例,没有进一步的解释。 - Aleksandar Makragić

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接