Open In App

Bokeh – grid layout of plots

Bokeh includes several layout options for arranging plots and widgets. They make it possible to arrange multiple components to create interactive dashboards or data applications. The layout functions let you build a grid of plots and widgets. You can nest as many rows, columns, or grids of plots together as you’d like. In addition, Bokeh layouts support a number of “sizing modes”. These sizing modes allow plots and widgets to resize based on the browser window.

Grid Layout :



Grid layout basically means all your plots will be in a grid-based format and those who have used some basic css, bootstrap can easily understand what grid represents.

How to install bokeh :



pip install bokeh

Basic Approach Of All Examples :

Example 1:

Syntax :

output_file("GFG.html")
currentList = list(range(7))
 
# writing logics for List1,List2,List2
# creating plots with these attributes 
# color,backgroundcolor,alpha ,size
# splots are f1,f2,f3
# using grid layout
show(gridplot([[f1, f2], [f3, None]], plot_width=200, plot_height=200))

Below is the implementation:




# python program for bokeh grid layout
from bokeh.io import output_file, show
from bokeh.layouts import gridplot
from bokeh.plotting import figure
 
# output will be produced in GFG.html
output_file("GFG.html")
 
# list will contain from 0 to 6
currentList = list(range(7))
 
# y0 is equals to x no change
List1 = currentList
 
# y1 square root of x
List2 = [i**0.5 for i in currentList]
 
# y2 square  of x
List3 = [i**2 for i in currentList]
 
# now creating plots f1,f2,f3
f1 = figure(background_fill_color="#27292e")
f1.triangle(currentList, List1, size=9, alpha=0.5, color="#de040f")
 
f2 = figure(background_fill_color="#27292e")
f2.circle(currentList, List2, size=9, alpha=0.5, color="#0828a8")
 
f3 = figure(background_fill_color="#27292e")
f3.square(currentList, List3, size=9, alpha=0.5, color="#b3810c")
 
# using grid layout on f1,f2,f3 plots
show(gridplot([[f1, f2], [f3, None]], plot_width=200, plot_height=200))

Output :

Example 2 :

Syntax :

output_file("GFG.html")
currentList = list(range(7))

# writing logics for List1,List2,List3
# creating plots with these attributes 
# color,backgroundcolor,alpha,size
# plots are f1,f2,f3
# using grid layout
show( gridplot([[f1, f2], [f3, None]], plot_width=200, plot_height=200))

Below is the implementation:




# python program for bokeh grid layout
from bokeh.io import output_file, show
from bokeh.layouts import gridplot
from bokeh.plotting import figure
 
# output will be produced in GFG.html
output_file("GFG.html")
 
# list will contain from 0 to 6
currentList = list(range(7))
 
# List1 is equals to currentList no change
List1 = currentList
 
# List2 square root of currentList
List2 = [abs(20-i) for i in currentList]
 
# List3 square  of currentList
List3 = [abs(i-i**0.5) for i in currentList]
 
# now creating plots f1,f2,f3
f1 = figure(background_fill_color="#27292e")
f1.triangle(currentList, List1, size=9, alpha=0.5, color="#de040f")
 
f2 = figure(background_fill_color="#27292e")
f2.circle(currentList, List2, size=9, alpha=0.5, color="#0828a8")
 
f3 = figure(background_fill_color="#27292e")
f3.square(currentList, List3, size=9, alpha=0.5, color="#b3810c")
 
# using grid layout on f1,f2,f3 plots
 
show(gridplot([[f1, f2], [f3, None]], plot_width=200, plot_height=200))

Output :


Article Tags :