Getting a strange result when trying to adjust the data range when plotting using contourf
import matplotlib
import numpy as np
import matplotlib.cm as cm
im
We can explicitly set the colorbar limits by sending a scalar mappable to colorbar.
CS = plt.contourf(X, Y, Z, 5, vmin = 0., vmax = 2., cmap=cm.coolwarm)
plt.title('Simplest default with labels')
m = plt.cm.ScalarMappable(cmap=cm.coolwarm)
m.set_array(Z)
m.set_clim(0., 2.)
plt.colorbar(m, boundaries=np.linspace(0, 2, 6))