Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh - multiple figures on same page

Tags:

django

bokeh

I have a need to have 2 bokeh figures on a page. I need them to separate from each other. Currently I can have only one figure (with multiple plots using grid/rows/columns) but not with multiple figures.

like image 413
Taposh DuttaRoy Avatar asked Oct 08 '16 06:10

Taposh DuttaRoy


People also ask

How do you plot multiple graphs on bokeh?

The easiest way to combine individual plots is to assign them to rows or columns. To display several plots in a vertical column layout, use the column() function instead. A more flexible way to arrange elements in Bokeh is to use the gridplot() function.

Is Bokeh a data visualization library?

Bokeh is a Python library for creating interactive visualizations for modern web browsers. It helps you build beautiful graphics, ranging from simple plots to complex dashboards with streaming datasets.


1 Answers

See the documentation on how to append figures in rows or columns.

For an example on how to plot figures in the same row see

from bokeh.io import output_file, show
from bokeh.layouts import row
from bokeh.plotting import figure

output_file("layout.html")

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

# create a new plot
s1 = figure(plot_width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)

# create another one
s2 = figure(plot_width=250, plot_height=250, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)

# create and another
s3 = figure(plot_width=250, plot_height=250, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)

# put the results in a row
show(row(s1, s2, s3))

Likewise, you could put the results in a column using

show(column(s1, s2, s3))

Of course, you can combine the two to create a grid, so if you have a list of figures, say graphs, you could do something like

cols = []
row_num = 3
for i in range(0, len(graphs), row_num):
    r = row(graphs[i: i + row_num])
    cols.append(r)
show(column(cols))
like image 191
nettrino Avatar answered Oct 26 '22 08:10

nettrino