0

I have a contour plot with data that goes from -90 to 90 degrees. for now i am using jet so I have a map that looks like this enter image description here

I have been asked to change the colormap so that instead of having a gradient, I have a fixed color for each 5 degress (so I believe 36 colors). Also i was thinking of maybe having same colors for the interval [5 10] and [-10 -5], and so on if that makes sense.

My code is quite long because i have a lot of data to process, but that's part of it just so you can see what function i am using to plot this

%%
x1=data(:,5); %x location
y1=data(:,16); %y location
z1=phi*90; %angle phi
z2=gamma*90; %angle gamma
n=300; precision of grid

%Create regular grid across data space
[X,Y] = meshgrid(linspace(min(x1),max(x1),n), linspace(min(y1),max(y1),n));

figure(3);
contourf(X,Y,griddata(x1,y1,z1,X,Y),100,'EdgeColor', 'None')
%title('Variation of In-plane angle \phi')
axis equal
axis ([0 8000 0 12000]) 
axis off
h=colorbar;
caxis([-90 90])
set(h, 'YTick', [-90:15:90])

Does anyone know how to create this colorbar? Cheers

1 Answers1

0

Every colormap-generating function in Matlab, including jet, takes an argument that specifies how many colormap entries there should be. In your case, you want 180 / 5 = 36 discrete colors:

colormap(jet(36))

To make sure the 36 colors cover exactly the 5 degree steps, set the color axis explicitly:

caxis([-90 90])

The result looks e.g. like this:

A. Donda
  • 8,381
  • 2
  • 20
  • 49
  • Thank A. Donda. It works fine, also what I did is create my own colormap matrix so that way I can have -90 and +90 the same color ( requested by my superrvisor because they are actually the same) – Dorian Kartalovski Mar 26 '15 at 15:50
  • You're welcome. Good that you already have it, otherwise you could have used a periodic colormap like `hsv`: starts with red and ends with red, and uses the whole spectrum of colors. – A. Donda Mar 26 '15 at 15:51
  • Yeah, use a hue colormap like `hsv`, jet is horrible in more ways than one... – rubenvb Mar 26 '15 at 15:52
  • @rubenvb, agreed, `jet` is ugly. – A. Donda Mar 26 '15 at 15:53