维护者注意:这个问题已经过时了。在
figure
上调用多个字形方法会自动组合(并且已经存在很多年了)。有关现代散景的信息,请参阅:
https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html
已过时:
我正在 IPython 笔记本中运行 Bokeh 教程。它仅显示散点图而不显示线图。从命令行它会单独渲染两个图。
如何在同一个图表中将两个图表放在一起?
import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
#bplt.output_notebook(url=None)
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()
过时的答案:请参阅https://docs.bokeh.org/en/latest/docs/user_guide/output/jupyter.html#jupyter-interactors* 现代 Bokeh
您只需在任何绘图命令之前调用
bplt.hold()
即可切换“保持状态”。以下代码对我有用:
import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
#bplt.output_notebook(url=None)
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)
bplt.hold() # <--- The important line!!
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()
过时的答案:请参阅https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html了解现代 Bokeh
尝试使用
figure
命令,如本示例所示:
import numpy as np
import bokeh.plotting as bplt
bplt.output_file("bokehtest.html")
x = np.linspace(-2*np.pi, 2*np.pi, 100)
y = np.cos(x)
bplt.figure()
bplt.line(x, y, color="red")
bplt.scatter(x, y, marker="square", color="blue")
bplt.show()