Python 3.x Bokeh-matplotlib-直方图-空白图

Python 3.x Bokeh-matplotlib-直方图-空白图,python-3.x,matplotlib,plot,bokeh,jupyter-notebook,Python 3.x,Matplotlib,Plot,Bokeh,Jupyter Notebook,我有以下代码运行在使用python 3的jupyter笔记本中: 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()) 这将为我绘制一个没有绘图的空白绘图。 是一个bug还是我做错了什么


我有以下代码运行在使用python 3的jupyter笔记本中:

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())
这将为我绘制一个没有绘图的空白绘图。


是一个bug还是我做错了什么?

看来plt.hist的行为有点像plt.plot和plt.show。如果在show(mpl.to_bokeh())之前调用plt.show(),您将得到与示例系统相同的结果,如下所示:

我不确定这种行为的根本原因,但解决方法是使用bokeh简单地创建直方图。如果您遵循bokeh的示例,这并不难:

对于问题中的示例,您可以执行以下操作:

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)
给予:


浏览器控制台中是否有任何输出?您好,我添加了一个图像,我应该更清楚。如果你可以共享浏览器控制台的输出(在Chrome中,它的设置->更多工具->开发人员工具),这将有助于诊断。这已经不可能了。自Bokeh 12.5(2017年4月)起,和
mpl.to_Bokeh()
已被删除。另见bryevdv。