As said in the comment, the command caxis
only update the colormap of the figure but will not modify your isolines previously created with contourf
.
since I don't have your data I build my example on the function peaks
, which I scale to be within range [-170 80]
%% // generate sample data set
x = linspace(0,1) ; [mesh_x , mesh_y] = meshgrid(x,x) ;
Z = peaks(100) ; Z(Z<0) = Z(Z<0) * -170./min(min(Z)) ; Z(Z>0) = Z(Z>0) * 80./max(max(Z)) ;
This, along with your current code, produce the following figure which indeed exhibit the same problem than in your example:

If you want your 20 isolines to be within the range [-10 10], you have 2 options, with slightly different output.
Option 1: modify call to contourf
The function contourf
has a parameter which allows you to specify where to place the isolines, so the simplest way is just to call contourf
with a parameter which will specify 20 isolines in the range [-10 10]
%% // method 1 : specify isolevels explicitely
h = figure ;
isolevels = linspace(-10,10,20) ;
contourf(mesh_x, mesh_y, Z, isolevels )
colormap(jet(20)) ; colorbar ; caxis([-10 10])
Which produces:

Now your isolines are evenly spread in the range you specified. I am not too sure why the values < -10 appear in white while the values>10 appear in the right saturated color.
edit: see the comment. To have the lowest contour filled you have to add an artificial isoline lower or equal to your lowest point in the surface. So if you replace your call to contourf
by:
contourf(mesh_x, mesh_y, Z, [min(min(Z)) isolevels] ) %// use this if you want the lowest contour to be filled
This will produce the same output than the solution below
Option 2: Saturate the underlying dataset yourself
It may not be the most elegant option, but at least it gets rid of the "white patch" problem in the solution above. The idea is to create another Z2, which will be a copy of Z for the range [-10 10] but every value outside of this range will be snapped to the range limit.
%% // method 2 : saturate the data yourself
h = figure ;
Z2 = Z ;
Z2(Z<=-10) = -10 ; %// snap every value<-10 to the value: -10
Z2(Z>= 10) = 10 ; %// snap every value>10 to the value: 10
contourf(mesh_x, mesh_y, Z2, 20)
colormap(jet(20)) ; colorbar ; caxis([-10 10])
This time your modify the underlying dataset to suit your need so you can call contourf
the same way your called it initially. This will produce the following output:
