I have tried the method from this question but it does not work, because the shape of my array is 3D, whereas the shape they use is 2D.
I begin with a 3-dimensional array
import numpy as np
import matplotlib.pyplot as plt
ins = np.load('ins.npy')
ex = ins[1]
ex.shape
# (60,60,1)
Now I plot the image.
ax = plt.gca()
im = ax.imshow(ex)
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(im, cax=cax)
I've searched for hours and, though this seems very simple, I haven't been able to find a way to create my own colorbar. I would like to use a colorscheme similar to the one employed by the weather service. The ticks would be:
ticks = [20,35,45,55,65,75]
I've tried doing:
x = [20,35,45,55,65,75]
colors = ["#eaa941", "#efef39", "#53a447", "#3b387f", "#48a2ba"]
cmap= mpl.colors.ListedColormap(colors)
cmap.set_under("crimson")
cmap.set_over("w")
norm= mpl.colors.Normalize(vmin=0,vmax=-70)
im = ax.contourf(x,x,ex, levels=[20,35,45,55,65,75],extend='both',cmap=cmap,norm=norm)
But no luck.