2013-12-11 32 views
5

我在IPython筆記本中運行Bokeh tutorial。它只顯示散點圖而不顯示線圖。在命令行中,它會呈現separately這兩個圖。IPython筆記本中的散景缺失情節

我該如何在同一張圖表中獲取兩張圖表?

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

@Jack,「散景」是由圖書館劫持的攝影術語。這裏有很多關於圖像處理和創建散景效果的問題(http://stackoverflow.com/search?q=bokeh)。如果沒有指定它是Python中的庫,人們會濫用它。請記住,沒有人真正閱讀維基摘錄... – Charles

+0

@Charles你沒有過濾掉該列表中的答案;並且只有少數[剩餘的問題](http://stackoverflow.com/search?q=bokeh+is%3Aquestion)實際上會談論效果本身。 –

回答

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

不......現在我把它們放在同一個單元格中,它們以兩個不同的圖表出來。 –

+0

@johnmangual查看我的編輯 –

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