在Matlab中创建颜色图 [英] Create a colormap in matlab
问题描述
我有一个等高线图,数据范围从-90到90度.现在我正在使用喷气机,所以我有一张看起来像这样的地图
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
已要求我更改颜色图,以便不使用渐变,而是对每5个色系使用固定的颜色(因此,我相信36种颜色).我也考虑过在[5 10]和[-10 -5]区间使用相同的颜色,依此类推.
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
推荐答案
Matlab中的每个生成颜色图的函数(包括jet
)都采用一个参数,该参数指定应有多少个颜色图条目.在您的情况下,您需要180/5 = 36种不连续的颜色:
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))
要确保36种颜色恰好覆盖5度步长,请明确设置色轴:
To make sure the 36 colors cover exactly the 5 degree steps, set the color axis explicitly:
caxis([-90 90])
结果看起来像像这样:
这篇关于在Matlab中创建颜色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!