Bokeh在jupyter notebook中打开时,往往绘制的图表会显示在自动打开的新的tab页面内,如何显示在本页中呢?
需要在项目中加入如下代码:
from bokeh.plotting import output_notebook
%matplotlib inline
output_notebook()
示例:
# 导入相关库
from bokeh.plotting import figure, output_notebook, show
% matplotlib inline
# 准备数据
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# 在notbook中展示
output_notebook()
# 创建一个带有标题和轴标签的新图表
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
# 添加带有图例和线条粗细的线图渲染器
#
p.line(x, y, legend="Temp.", line_width=2)
# 显示图表
show(p)
参考:https://blog.csdn.net/shs867/article/details/102763268