I'm trying to set the colour of my colourbar at the value of 0 to white. I've already tried that, but I keep getting the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'DivergingNorm' is not defined
>>> colormesh= m.contourf(x,y,val,32, tri=True, cmap = 'RdBu_r')
<stdin>:1: UserWarning: The following kwargs were not used by contour: 'tri'
My code looks like this:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits import basemap
from matplotlib.colors import DivergingNorm
lat=np.array([18,20,23, 50])
lon=np.array([-10, 40, 50, -60])
val=np.array([-3, 8, -10, -50])
m = basemap.Basemap(projection='robin', lon_0=0, lat_0=0, resolution='l',area_thresh=1000)
m.drawcoastlines(color = 'black')
x,y = m(lon,lat)
norm = DivergingNorm(vmin=val.min(), vcenter=0, vmax=val.max())
colormesh= m.contourf(x,y,val,32, tri=True, norm=norm, cmap = 'RdBu_r')
plt.colorbar(location='bottom',pad=0.04,fraction=0.06)
plt.show()
I have seen that this works in colormesh but not yet in contourf although according to the documentation norm should exist.