For the contourf function (last code block) the extend='both' parameter has to be passed into the contourf() function and removed from the colorbar() function in order to work and to not get a warning.