I'm trying to create a color bar with 13 levels and use a diverging RdBu_r colormap with the central value spaced at 0. Currently, I have an evenly spaced colorbar with values descending by 8 ranging from -48 to +48
What I would like to make is a colorbar with even colored spacing, but unevenly spaced values, like this colorbar which I modified in photoshop, such that the values go from [-96.0, -72, -48, -24, -12, -6, 0, 6, 12, 24, 48, 72, 96]
My current attempt looks like this:
from cartopy import crs as ccrs; import matplotlib.pyplot as plt
crs_new = ccrs.PlateCarree()
fig, axs = plt.subplots(subplot_kw={'projection': crs_new},figsize=(8, 6))
cmap = 'RdBu_r'
uneven_levels = [-96.0, -72, -48, -24, -12, -6, 0, 6, 12, 24, 48, 72, 96]
vmin,vmax = -48,48
cs=plt.pcolormesh(lon,lat, data,cmap=cmap, transform=crs_new,vmin=vmin,vmax=vmax)
cbar=plt.colorbar(cs,boundaries= uneven_levels)
Which results in a colorbar with really dark ends and clearly uses linearly spaced coloring.
Using countourf and "spacing = uniform" did not work.
Using "colors.DivergingNorm(vmin=vmin, vcenter=0, vmax=vmax)" did not work.
I've tried to define my own color bar with
cmap = plt.get_cmap('RdBu_r')
colors = cmap(np.linspace(0, 1, len(uneven_levels)))
but have no idea to get the data to match up with these levels, results in the same thing as figure 3, so this also did not work.
Any help is greatly appreciated! :)
