Plot multiple surfaces on same plot with different color for each surface

196 views (last 30 days)
Hi. I have to superimpose several surfaces on the same plot, something like:
surf(X1,Y1,Z1); hold on
surf(X2,Y2,Z2); hold on
surf(X3,Y3,Z3); hold on
... etc
This shows all surfaces with the same color scheme. I would like to show each surface with a different color map. Does anybody have suggestions? Many thanks.
  1 Comment
Anant Gairola
Anant Gairola on 13 Nov 2016
I have the same question. Did you find an answer? I have three surface plots, one on each xy, xz and yz planes. I want a different color bar scheme for each surface plot.

Sign in to comment.

Answers (2)

Sean de Wolski
Sean de Wolski on 18 May 2012
Like this:
figure;hold on
[xx yy] = meshgrid(1:10);
colormap([1 0 0;0 0 1]) %red and blue
surf(xx,yy,rand(10),ones(10)); %first color (red)
surf(xx,yy,rand(10)+10,ones(10)+1); %second color(blue)
view(17,22)
?

Wagih Abu Rowin
Wagih Abu Rowin on 15 Feb 2021
You can specify the color for each surface individually like:
close all
figure;
%surf 1
surf(peaks+5,'FaceLighting','gouraud',...
'MeshStyle','column',...
'SpecularColorReflectance',0,...
'SpecularExponent',5,...
'SpecularStrength',0.2,...
'DiffuseStrength',1,...
'AmbientStrength',0.4,...
'AlignVertexCenters','on',...
'LineWidth',0.2,...
'FaceAlpha',0.2,...
'FaceColor',[0.07 0.6 1],...
'EdgeAlpha',0.2);
hold on
%surf 2
surf(peaks,'SpecularExponent',1,...
'SpecularStrength',1,...
'DiffuseStrength',1,...
'AmbientStrength',0.4,...
'FaceColor',[0.5 0.5 .5],...
'AlignVertexCenters','on',...
'LineWidth',0.2,...
'EdgeAlpha',1);
The results look like this:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!