Reputation: 655
I am trying to plot radar data in bokeh from an hdf5 file. I've stored the data into a 2d array that is 1800*3600. When I try to plot the data using p.image
it shows up black with some splotches which i'm assuming is where the data is greater than 0, but it doesn't conform to the palette i've specified. I'm not sure why this is occurring.
f = h5py.File(fname, 'r')
lat = f['Grid']['lat']
lon = f['Grid']['lon']
precip = f['Grid']['precipitationCal']
precip = np.transpose(precip)
d = np.empty((1800,3600))
for (x,y), value in np.ndenumerate(precip):
if value <= 0:
d[x,y]=np.nan
else:
d[x,y]=value
output_file("testimage.html", title="image.py example")
p = figure(x_range = [0, 3600], y_range=[0, 1800])
p.image(image=[d],x=[0],y=[0],dw=[3600], dh=[1800], pallete="Spectral-256")
show(p)
Upvotes: 1
Views: 510
Reputation: 2137
Two things:
First, the argument to pass to p.image is spelled "palette" not "pallete". The default palette is Grey9, which would give you the colormap you have.
Second (and the docs are sort of unclear on this), the palette argument accepts a list containing the colormap as hex values. This can be either an arbitrary list:
palette = ["#8c9494", "#8398a2", "#7c9baa"]
p.image(image=[d],x=[0],y=[0],dw=[360], dh=[180], palette=palette)
or a standard palette from Bokeh
from bokeh.palettes import Spectral6
p.image(image=[d],x=[0],y=[0],dw=[360], dh=[180], palette=Spectral6)
Note:
print(Spectral6)
> ['#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59', '#d53e4f']
https://docs.bokeh.org/en/latest/docs/reference/palettes.html
Upvotes: 1