Using Layouts for Multiple Plots:
- While plotting multiple plots, it is always best to make use of layouts in order to display the plots side by side, or vertically on top of each other.
- This makes comparison of multiple plots much easier to interpret than if you were to create separate cells in your Jupyter Notebook.
Create Multiple Plots Along the Same Row:
- Once the data is wrangled/loaded and cleaned, and after the figures are instantiated, the row function can be used to display the plots side by side.
- The row function is part of the bokeh.layouts module. The below code snippet demonstrates how to use the row function to display two plots side by side.
python
1from bokeh.plotting import figure, show, output_notebook
2from bokeh.models import ColumnDataSource
3from bokeh.layouts import row
4import pandas as pd
5
6# --- snip ---
7
8# Create the figures
9fig1 = figure()
10fig2 = figure()
11
12# Use row layout to place figures side by side
13both_figs = row(fig1, fig2)
14
15# Display the layout
16show(both_figs)Create Multiple Plots Vertically on Top of Each Other:
- Similarly, once the data is wrangled/loaded and cleaned, and after the figures are instantiated, the column function can be used to display the plots side by side.
- The column function is part of the bokeh.layouts module. The below code snippet demonstrates how to use the column function to display two plots vertically on top of each other.
python
1from bokeh.plotting import figure, show, output_notebook
2from bokeh.models import ColumnDataSource
3from bokeh.layouts import column
4import pandas as pd
5
6# --- snip ---
7
8# Create the figures
9fig1 = figure()
10fig2 = figure()
11
12# Use column layout to place figures vertically on top of each other
13both_figs = column(fig1, fig2)
14
15# Display the layout
16show(both_figs)Create Multiple Plots In a Row and Column:
- Similar to the above examples, once the data is wrangled/loaded and cleaned, and after the figures are instantiated, the column and row functions can be used to display a combination of horizontal and vertical plots in a nested layout.
- The below code snippet demonstrates how to use the column and row functions to display a nested layout of plots.
python
1from bokeh.plotting import figure, show, output_notebook
2from bokeh.models import ColumnDataSource
3from bokeh.layouts import row, column
4import pandas as pd
5
6# --- snip ---
7
8# Create the figures
9fig1 = figure()
10fig2 = figure()
11fig3 = figure(width_policy='max')
12
13# Use column and row layout to display a nested layout of plots.
14all_figs = column(row(fig1, fig2), (fig3))
15
16# Display the layout
17show(all_figs)