五、多图展示

from bokeh.io import output_notebook, show
from bokeh.plotting import figure

output_notebook()

在前面的章节中, 我们学习的都是在一张画布上展示不同的数据。 但是我们时常需要在一张画布上展示多张图。

下面这段数据的定义将要用于后面的案例中.

x = list(range(11))
y0, y1, y2 = x, [10-i for i in x], [abs(i-5) for i in x]  

画布行布局与列布局

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 分别代表三个画布。 建立好三画布后, 通过row()进行展示, 也就是说, 它们在水平线上展示一排。

网格布局

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

通过gridplot定义网格的布局

下一章:六、图片联动

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容