美文网首页
五、多图展示

五、多图展示

作者: Bllose | 来源:发表于2021-03-15 19:39 被阅读0次
    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定义网格的布局

    下一章:六、图片联动

    相关文章

      网友评论

          本文标题:五、多图展示

          本文链接:https://www.haomeiwen.com/subject/ckhlcltx.html