How do I set a surf to one color (no gradient) in my matlab-plot?

Completing the answer from gnovice, an extra ingredient in set(hsurface...) may be required (Matlab R2010b 64):

hSurface = surf(...your arguments to create the surface object...);
set(hSurface, 'FaceColor',[1 0 0], 'FaceAlpha',0.5, 'EdgeAlpha', 0);

to make invisible the point-to-point edges of the plotted surface


The easiest way to create a surface that has just 1 color and a given transparency value is to set the 'FaceColor' and 'FaceAlpha' properties of the surface object:

hSurface = surf(...your arguments to create the surface object...);
set(hSurface,'FaceColor',[1 0 0],'FaceAlpha',0.5);

This example sets the surface color to be red and the transparency to 0.5. You can also set the edge properties too (with 'EdgeColor' and 'EdgeAlpha').


It is not clear to me what you want to do. When you say one color for the surf, do you mean exactly one color, or do you mean you want shades of gray?

Here is some code that will do a variety of things, you can choose which lines to use:

x = rand(1,20);
y = rand(1,20);
z = rand(1,20);

[X,Y] = meshgrid(linspace(0,1,10),linspace(0,1,10));
Z = rand(10)*0.1;

clf
plot3(x,y,z,'.');
hold on
h = surf(X,Y,Z)
hold off

%% This will change the color
colormap(copper)
%% This will remove colordata
set(h, 'cdata',zeros(10))
%% This will make transparent
alpha(0.5)