点形状文件的颜色栏

时间:2015-09-16 14:36:22

标签: matlab mapping

[![在此输入图像说明] [1]] [1]您好我使用geoshow功能在美国地图上绘制了点形状文件。示例代码在这里:

for i = 1:length(X_1991_05) if (X_1991_05(i,3) <= -0.7); h1 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('DarkRed'),'MarkerSize',9,'Marker', 'o'); hold on; %,'MarkerSize',2,

elseif(X_1991_05(i,3) > -0.7 && X_1991_05(i,3) < -0.6);
        h2 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('DarkOrange'),'MarkerSize',9,'Marker', 'o'); hold on;


elseif(X_1991_05(i,3) > -0.6 && X_1991_05(i,3) < -0.5);
        h3 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('DarkKhaki'),'MarkerSize',9,'Marker', 'o'); hold on;    


elseif(X_1991_05(i,3) > -0.5 && X_1991_05(i,3) < -0.4);
       h4 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('Gold'),'MarkerSize',9,'Marker', 'o'); hold on;    


elseif(X_1991_05(i,3) > -0.4 && X_1991_05(i,3) < -0.2);
      h5 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('Khaki'),'MarkerSize',9,'Marker', 'o'); hold on;    


elseif(X_1991_05(i,3) > -0.2 && X_1991_05(i,3) < 0.2);
       h6 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('Beige'),'MarkerSize',9,'Marker', 'o'); hold on;    


elseif(X_1991_05(i,3) > 0.2 && X_1991_05(i,3) < 0.4);
       h7 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('Aqua'),'MarkerSize',9,'Marker', 'o'); hold on;    


elseif(X_1991_05(i,3) > 0.4 && X_1991_05(i,3) < 0.5);
        h8 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('CornflowerBlue'),'MarkerSize',9,'Marker', 'o'); hold on;    

elseif(X_1991_05(i,3) >= 0.5);
       h9 = geoshow(Lat,Lon,'DisplayType','point','MarkerEdgeColor','k','MarkerFaceColor',rgb('Navy'),'MarkerSize',9,'Marker', 'o'); hold on;
 end

现在我想根据值h1 .... h9添加一个颜色条吧?此处显示了一个示例:enter image description here

我不知道该怎么做......有什么帮助?

[1]:http://i.stack.imgur.com/ZKJeK.jpg:如果我在代码中使用colorbar,我会得到如图2所示的图片(附件链接)

1 个答案:

答案 0 :(得分:0)

确定。因此,您正在使用自己的色彩映射表,这就是为什么单个colorbar命令无法帮助您,因为您还没有告诉MATLAB您使用的色彩映射表是什么。

在您的情况下,您可以像这样设置色彩映射:

cmap = zeros(9,3);
cmap(1,:) = (139, 0, 0);
cmap(2,:) = (255, 140, 0);      % rgb code for dark orange
cmap(3,:) = (189, 183, 107);    % dark khaki
cmap(4,:) = (255, 215, 0);      % gold
cmap(5,:) = (240, 230, 140);    % Khaki
cmap(6,:) = (245, 245, 220);    % Beige
cmap(7,:) = (127, 255, 212);    % Aquamarine
cmap(8,:) = (100, 149, 237);    % Cornflower blue
cmap(9,:) = (0, 0, 128);        % Navy
cmap = cmap/255;  % MALTAB takes rgb indexes in the range [0 1]

然后你就可以使用这样的色彩图:

if (X_1991_05(i,3) <= -0.7)
        h1 = geoshow(Lat, Lon, 'DisplayType', 'point', 'MarkerEdgeColor', 'k', 'MarkerFaceColor', cmap(1,:), 'MarkerSize',9, 'Marker', 'o'); hold on;
....

你必须告诉MATLAB你正在使用哪个色彩图,这样才能为你生成一个合适的色条:

colormap(cmap)
colorbar