I am trying to create a filled contour plot in matplotlib using colormap.
I want to change color of the specified value.
For example,
levs = [-3,-1,1,3]
plt.contourf(x,y,z,levs,cmap=cm.jet,extend='both')
I hope the color between -1 and 1 to white keeping the other colors default colormap.
Sorry for my bad english.
Any help would be appreciated.
I would just overplot the same contour plot, but then just with levels between -1 and 1, with color white.
For example:
Update
In case you want more control, set the
colorskeyword incontourfto a tuple of matplotlib colors, with the same number of elements as you have levels (minus 1: the colors correspond to the intervals between your level boundaries). Then, you don’t need to overplot a separate contour, and your colorbar is also correct:Even nicer perhaps is to define your own colormap, but then you’ll likely run into the issue that you have to match your colormap exactly with your contour levels. Which is the why, conveniently,
colorskeyword exists.