import xarray as xr
import hvplot.xarray
from bokeh.models import FixedTicker
ds = xr.tutorial.open_dataset('air_temperature')
# uneven color levels / intervals
# absolute 0, cryogenic, freezing, comfortable, boiling, extreme
color_levels = [0, 150, 273.15, 293.15, 373.15, 500]
ds.hvplot("lon", "lat").opts(
# select colors to create color map
cmap=["black", "#336699", "#FF8C00", "#B22222", "#8B008B"],
# set color levels and color bar ticks
color_levels=color_levels,
colorbar_opts={"ticker": FixedTicker(ticks=color_levels)},
# set color bar range based on color levels
clim=(color_levels[0], color_levels[-1]),
)
108. Want to align colorbar ticks with uneven color levels and custom colors?
May be useful to align the colorbar intervals with intuitive intervals such as freezing, room, and boiling point temperatures.
#python #dataviz #holoviews #datascience