Adnan Ali
Adnan Ali

Reputation: 111

How do I change color of surface plot in Matlab

I am trying to plot a surface. However, I do not much understand how to change the color of the plot. I have studied and tried various options without much success. Here is the code for the surface plot:

clear all;
[X,Y]=meshgrid(-10:.1:10);

p=X;

[X, Y] = meshgrid(-20:.2:20);

q=Y;

a = 10;
b = 20;

Z=2*a.*p+p.^2-2*b.*q-q.^2;

figure;

H=surf(p,q,Z)

xlim([-10 10]);
ylim([-20 20]);

% colormap jet;

hold on;

view([150 25]);

xlabel('p');
ylabel('q');
zlabel('The Data Z');

print -r600 -depsc Figure.eps;

I have tried different colormap with jet, winter or hsv arguments. I have also tried various options similar to the following:

c = jet(6);
colormap(c);

However, all I get is a figure with dark shade like the following:

Surface plot with dark colors

I would like to change the colors of the surface plot to something lighter, e.g. shades of light blue, cyan or light green. Any help with this will be much appreciated.

Thanks in advance,

A.

Upvotes: 1

Views: 4017

Answers (1)

rinkert
rinkert

Reputation: 6863

You are predominantly seeing the edges right now, which are black by default. There is a couple things you can do.

  1. Hide the edges completely
H.EdgeColor = 'none';
  1. Set some alpha value (transparency) to the edges
H.EdgeAlpha = 0.5;
  1. Plot your data once with a very fine grid (as you do now) using surf, set the edge color to 'none', plot your data with a rough meshgrid using mesh to show lines, making it easier to see the plane.
% generate data
a = 10;
b = 20;

xv = -10:.1:10;
yv = -20:.2:20;
[X,Y]=meshgrid(xv,yv);

Z=2*a.*X+X.^2-2*b.*Y-Y.^2;

% make data more course.
xv_course = -10:1:10;
yv_course = -20:1:20;
[Xc,Yc]=meshgrid(xv_course,yv_course);
Zc = 2*a.*Xc+Xc.^2-2*b.*Yc-Yc.^2;

figure(1); clf; 
Hs = surf(X,Y,Z, 'EdgeColor', 'none');
colormap cool
hold on;
Hm = mesh(Xc,Yc,Zc, 'EdgeColor', 'k', 'FaceColor', 'none');

view([150 25]);

xlabel('x');
ylabel('y');
zlabel('The Data Z');

enter image description here

Upvotes: 3

Related Questions