Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a 2d array with bokeh?

Tags:

python

bokeh

Can someone give a short/simple example of how to plot a 2D-array with bokeh? Something similar to imshow() in matplotlib. I did not find a good examples given in the bokeh gallery.

a = np.array([[1,2], [3, 4]])
imshow(a)  # but with bokeh
like image 624
Soren Avatar asked May 18 '18 22:05

Soren


People also ask

How do you plot in bokeh?

plotting : A high level interface for creating visual glyphs. The dataset used for generating bokeh graphs is collected from Kaggle. To create scatter circle markers, circle() method is used. To create a single line, line() method is used.

Does bokeh work with pandas?

Pandas-Bokeh provides a Bokeh plotting backend for Pandas, GeoPandas and Pyspark DataFrames, similar to the already existing Visualization feature of Pandas. Importing the library adds a complementary plotting method plot_bokeh() on DataFrames and Series.

What is ColumnDatasource bokeh?

Advertisements. Most of the plotting methods in Bokeh API are able to receive data source parameters through ColumnDatasource object. It makes sharing data between plots and 'DataTables'. A ColumnDatasource can be considered as a mapping between column name and list of data.


1 Answers

Thanks Adian! That was a good direction. Here is a minimal example.

import numpy as np
from bokeh.plotting import figure, show

a = np.array([[1,2], [3, 4]])
p = figure(x_range=(0, 2), y_range=(0, 2))

# must give a vector of image data for image parameter
p.image(image=[a], x=0, y=0, dw=2, dh=2, palette="Spectral11")

show(p)
like image 193
Soren Avatar answered Oct 23 '22 06:10

Soren