Create a colormap in matlab [duplicate]

狂风中的少年 提交于 2019-12-12 01:47:53

问题


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

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:


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:



来源:https://stackoverflow.com/questions/29262269/create-a-colormap-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!