Set colors for extended colorbar

Dear CDS-Team,

during my plot of a geomap I was looking for a solution to plot values higher/lower than the colorbar range in a different color.

In this example the color for lower values (<5) should be grey and for higher values (>20) black.

My research ended with the result that there is a "set_under" and "set_over" feature to set the colors. Unfortunately my tries to include them weren't successful and Im not sure where to place them.

Or should I otherwise try to create a own colormap or somehow adjust the "YlGnBu" colormap?


Thanks and cheers,

Tim




import cdstoolbox as ct

@ct.application()
@ct.output.figure()

def application():
precipitation = ct.catalogue.retrieve(
‘reanalysis-era5-land-monthly-means’,
{
‘product_type’: ‘monthly_averaged_reanalysis’,
‘variable’: ‘total_precipitation’,
‘year’: ‘2003’,
‘month’: ‘01’,
‘time’: ‘00:00’,
}
)
figure = ct.cdsplot.geomap(precipitation,
pcolormesh_kwargs={
‘cmap’: ‘YlGnBu’,
‘vmin’: 5,
‘vmax’: 20,
‘cbar_kwargs’:{
‘orientation’: ‘vertical’,
‘shrink’: 0.67,
‘extend’:‘both’,
},
‘levels’: 11,
},
projection=ct.cdsplot.crs.PlateCarree()
)
figure.ax.grid(True)

return figure



I have also encountered this issue and I would be interested to know the answer to Tims question as well.