1

I'm trying to plot an xarray dataset in Geoviews, like this:

https://geoviews.org/gallery/bokeh/xarray_image.html#bokeh-gallery-xarray-image

There I can define a colormap by cmap.

The cmap is just a list of hex-codes, like:

['#150b00', '#9b4e00', '#f07800', '#ffa448', '#a8a800', '#dddd00', '#ffff00', '#ffffb3', '#ffffff', '#b0ffff', '#00e8e8', '#00bfbf', '#008a8a', '#79bcff', '#0683ff', '#0000c1', '#000048']

I want to define to levels of values for these color, like this list:

[-10.0, -5.0, -2.5, -1.0, -0.5, -0.2, -0.1, -0.05, 0.05, 0.1, 0.2, 0.5, 1.0, 2.5, 5.0, 10.0]

How can I define these levels?

hotoats
  • 75
  • 1
  • 5

1 Answers1

0

Please try to set the parameter color_levels to the wanted values. This is explained in HoloViews Styling Plots in the section Custom color intervals. HoloVies is the source where the gv.Image comes from. Therefore this should work.

cmap = ['#150b00', '#9b4e00', '#f07800', '#ffa448', '#a8a800', '#dddd00', '#ffff00', '#ffffb3', '#ffffff', '#b0ffff', '#00e8e8', '#00bfbf', '#008a8a', '#79bcff', '#0683ff', '#0000c1', '#000048']
levels = [-10.0, -5.0, -2.5, -1.0, -0.5, -0.2, -0.1, -0.05, 0.05, 0.1, 0.2, 0.5, 1.0, 2.5, 5.0, 10.0]

images.opts(
    cmap=cmap,
    color_levels=levels,
    colorbar=True,
    width=600, 
    height=500) * gf.coastline

Comment

If this is not working, then I apologize. In the moment I am not able to install GeoViews on my machine.

mosc9575
  • 5,618
  • 2
  • 9
  • 32