我有以下代码在 jupyter笔记本中运行 python 3 :
from bokeh import mpl
from bokeh.plotting import figure, show, output_notebook
import matplotlib.pyplot as plt
output_notebook()
plt.hist([1,2,3,3,3,3,4,5,4])
show(mpl.to_bokeh())
答案 0 :(得分:1)
似乎plt.hist的行为有点像plt.plot和plt.show。如果在show(mpl.to_bokeh())之前调用plt.show(),您将获得与示例系统相同的结果,如下所示:
我不确定这种行为的根本原因,但解决方法是简单地使用散景创建直方图。如果您遵循散景示例,这并不难:http://bokeh.pydata.org/en/0.11.1/docs/gallery/histogram.html
对于您问题中的示例,您可以执行以下操作:
from bokeh import mpl
import numpy as np
from bokeh.plotting import figure, show, output_notebook, vplot
output_notebook()
hist, edges = np.histogram([1,2,3,3,3,3,4,5,4])
p1 = figure(title="Bokeh Hist",background_fill_color="#E8DDCB")
p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
fill_color="#036564", line_color="#033649")
show(p1)
,并提供: