Bokeh在IPython笔记本中丢失绘图。

5

维护者注意:这个问题已经过时了。在figure上调用多个glyph方法会自动合并(并且已经有很多年了)。有关现代Bokeh的信息,请参见:

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

@Jack,“bokeh”是一个被库占用的摄影术语。这里有很多关于图像处理和创建bokeh效果的问题。如果没有指定它是Python中的一个库,人们就会滥用它。记住,没有人真正阅读维基摘录... - Charles
@Charles,您没有从列表中过滤掉答案;并且只有少数剩余问题实际上讨论了效果本身。 - Ja͢ck
2个回答

3

已过时的答案:请参阅现代Bokeh的https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html*



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

页面通过URL获取现代Bokeh的答案显示404错误。 - undefined

1

过时的答案:请参见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()

现在我将它们放在同一个单元格中,然后它们会分别出现在两个不同的图表中。 - john mangual

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接