from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
在前面的章節(jié)中, 我們學(xué)習(xí)的都是在一張畫(huà)布上展示不同的數(shù)據(jù)。 但是我們時(shí)常需要在一張畫(huà)布上展示多張圖。
下面這段數(shù)據(jù)的定義將要用于后面的案例中.
x = list(range(11))
y0, y1, y2 = x, [10-i for i in x], [abs(i-5) for i in x]
畫(huà)布行布局與列布局
from bokeh.layouts import row
# create a new plot
s1 = figure(width=250, plot_height=250)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)
# create another one
s2 = figure(width=250, height=250)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
# create and another
s3 = figure(width=250, height=250)
s3.square(x, y2, size=10, color="olive", alpha=0.5)
# show the results in a row
show(row(s1, s2, s3))
row_plots.PNG
上面代碼中, s1, s2, s3 分別代表三個(gè)畫(huà)布。 建立好三畫(huà)布后, 通過(guò)row()進(jìn)行展示, 也就是說(shuō), 它們?cè)谒骄€(xiàn)上展示一排。
網(wǎng)格布局
from bokeh.layouts import gridplot
# create a new plot
s1 = figure(width=250, plot_height=250)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)
# create another one
s2 = figure(width=250, height=250)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
# create and another
s3 = figure(width=250, height=250)
s3.square(x, y2, size=10, color="olive", alpha=0.5)
# put all the plots in a gridplot
p = gridplot([[s1, s2], [s3, None]], toolbar_location=None)
# show the results
show(p)
grap_plots.PNG
通過(guò)gridplot定義網(wǎng)格的布局