我正在尝试从hdf5文件中绘制散景中的雷达数据。我已将数据存储到1800 * 3600的二维数组中。当我尝试使用p.image
绘制数据时,它显示黑色,带有一些splotches,我假设它是数据大于0的地方,但它不符合我指定的调色板。我不确定为什么会这样。
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)
答案 0 :(得分:1)
两件事:
首先,传递给p.image的参数拼写为&#34; palette&#34;不是&#34; pallete&#34;。默认调色板是Grey9,它可以为您提供色彩映射。
其次(并且文档对此有点不清楚),palette参数接受包含colormap为hex值的列表。这可以是任意列表:
palette = ["#8c9494", "#8398a2", "#7c9baa"]
p.image(image=[d],x=[0],y=[0],dw=[360], dh=[180], palette=palette)
或来自Bokeh的标准调色板
from bokeh.palettes import Spectral6
p.image(image=[d],x=[0],y=[0],dw=[360], dh=[180], palette=Spectral6)
注意:
print(Spectral6)
> ['#3288bd', '#99d594', '#e6f598', '#fee08b', '#fc8d59', '#d53e4f']
来源:http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html