在IPython笔记本中散景失踪的情节

时间:2013-12-11 20:46:23

标签: ipython-notebook bokeh

我在IPython笔记本中运行Bokeh tutorial。它仅显示散点图而不显示线图。从命令行,它渲染两个图separately

如何将两张图表放在同一张图表中,相互叠加?

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()

2 个答案:

答案 0 :(得分:3)

您只需在任何绘图命令之前调用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()

答案 1 :(得分:2)

尝试使用此示例中的figure命令: http://bokeh.pydata.org/plot_gallery/correlation.html

换句话说:

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()