how to color a surface plot

조회 수: 9 (최근 30일)
Abhinav
Abhinav 2015년 11월 25일
댓글: Star Strider 2015년 11월 28일
I have plotted a surface plot using meshgrid as shown below
However I want to change the color to the ones shown in the example on mathworks: http://in.mathworks.com/help/matlab/learn_matlab/creating-mesh-and-surface-plots.html, I have surf too, but it didn't work. Can anyone please help me?

채택된 답변

Star Strider
Star Strider 2015년 11월 25일
My guess is that you are referring to the plot in the Colored Surface Plots section of that documentation, created by this code:
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
surf(X,Y,Z)
colormap hsv % <— Specify ‘colormap’ To Override Default
colorbar
You need to add this line:
colormap hsv
to your code to get the same colormap as in the example plot.
  댓글 수: 2
Abhinav
Abhinav 2015년 11월 28일
This is helpful, Thanks a lot. can you also tell me what to do if have to view the surface plot in 2D. I used view(2) and it shows a plot as drawn below. The problem is that the first is complete white which is wrong, the yellow column should actually be the first column.
Basically, I have a 21x30 matrix which I want show on a 2d color plot, each cell corresponds to Z value for a pair X and Y. How to do it?
Star Strider
Star Strider 2015년 11월 28일
My pleasure.
I don’t have your data, so you will have to do the experiment and tell me the result.
See if adding:
axis tight
after the plot does what you want.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by