A simple question.
Is there anyway to tell the Matlab function "contourf", to scale the colors with my given values (and not the dataset's values) ?
I know that you can call the function simply by
contourf(x,y,Data, v)
and setting the range in the v vector, but my problem is that Matlab automatically checks whether or not the specified values in the v vector does actually exist in the Data? If they don't exist, then it automatically rescales the color range back to the maximum and minimum available in the dataset.
For instance, if
Data =[0 1 2; 3 4 5; 6 7 8];
v=-10:1:10;
then when I call
contourf(x,y,Data,v)
the colormap shown scales itself with
v=[0:8];
The reason I am asking for this is that I would like to several contour plots for various datasets, but I need to always have the same colorcode associated with the maximum/minimums that might not be necessarily in the current data array passed to the contourf function.
I hope I was clear enough.
Best Answer
Have a look at the
caxis
command. I haven't tested it withcontourf
, but I think this is what you're after.Use it like so:
where
cmin
andcmax
are the minimum and maximum colors given as indices into the current color map. Fromhelp caxis
:meaning you can also tinker with these axes settings manually (i.e.,
set(gca, 'clim', [...])
)