Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom colour for matlab surface plot

I have loaded in some topographic data to matlab, and created surf, surfl and contour plots of this data, colouring them using colormap. The topographic data ranges from 0 to 2500 m.

I want to plot a map that colours any topography below 200 m blue, above 500 m red, and between 200 and 500 m green. Is it possible to do this? Could anyone give me any tips regarding the command required to do so?

Many thanks

like image 756
user3035970 Avatar asked Feb 15 '23 13:02

user3035970


2 Answers

You may play with colormap and the fourth input of surf.

The following plot

enter image description here

is produced by

[X,Y,Z] = peaks(1000);

%colormap
cmap = [0.6 0.2 0.4; 
        0.5 0.5 0.5; 
        0.1 0.9 0.9];  

Zcolor = zeros(size(Z));                   
threshold = 2;
Zcolor(Z <= -threshold)                 = 1;  % first row of cmap
Zcolor(Z > -threshold & Z < threshold)  = 2;  % second row of cmap
Zcolor(Z >= threshold)                  = 3;  % third row of cmap

figure('Color','w');
surf(X, Y, Z, Zcolor, 'EdgeColor', 'None');
colormap(cmap); 
light('Position', [0 -2 1])
like image 57
marsei Avatar answered Feb 23 '23 19:02

marsei


hsurf=surf(...)
set(hsurf,'FaceColor','interp')

doc surf for more information.

like image 40
user2987828 Avatar answered Feb 23 '23 19:02

user2987828