## Matlab Contour Plot with Absolute Colors instead of relative per plot

### Matlab Contour Plot with Absolute Colors instead of relative per plot

I am using the filled contour plot function (contourf) to generate a series of contour plots. I am using a vector to define the contour levels.

Lets say that for 1000 sets of data with Z values ranging from 0-100, I am making a contour plot for each data set. Each contour plot should have potentially 10 levels, predefined, based on the bottom 10% of data values up to the top 10% of values. But if a particular set of data only contains values in the middle 50%, (from about 25-75) I want the color to represent this as well as the contour lines.

Currently, each plot goes from blue to red regardless of the vector defined levels. I want blue to represent an absolute Z value across all my contour plots, instead of being redefined per plot.

All help is appreciated.

Thank you.

check out:

caxis

-andrew

### Matlab Contour Plot with Absolute Colors instead of relative per plot

I believe that I have found a way to do this. Consider the following example.

1. Suppose Z is your matrix of data and it includes values in the interval [10,34]. However, you want your colormap to reflect values in the interval [0,50].

2. Save Z under another name: Z2=Z.

3. Set one element of Z equal to 0 and another element of Z equal to 50.

4. Create a contour map using Z. This contour map has the colormap you desire. However, it does not reflect your data because of the changes made in step 3.

5. Now use the "hold on" command and then create another contour map using Z2. This will yield a contour map of your data with the colormap you desire.

Here's the code. (Adding the lines maked with "*****" achieves the desired outcome.)

close all
clear all

Z = [10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34 ];

[X,Y] = meshgrid(1:1:5);

hf=figure;

levels = [0 5 10 15 20 25 30 35 40 45];

Z2=Z % *****
Z(1,1)=1; Z(1,2)=50; % *****

contourf(Z,levels);

hold on; % *****
contourf(Z2,levels); % *****