Modify Surface plot display format
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to plot a 3d surface and I have succeeded with it, but Im having an issue with representing it in the format that is available in a reference resource. The reference resource has like curved boundaries to each color on the surface while the plot I have has only one color appear in each square. Is it possible to have multiple colors in each square as shown in the figure below?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1705016/image.png)
Currently, I have raw data that I fit. Then I create a meshgrid with 10x10 points in x and y, and then query this sfit object to get the z values. These x,y,z values are plotted using the surf function. And then for the color I customize the colorbar for single colors for 0.5 increments of z value from 1 being aqua, 1.5 being turquoise and so on...
I would really appreciate some leads on what should change. I have a hunch that its something to do with the way I create a mesh, but Im not sure how to create a non square mesh.
Thank you for your time and help!
댓글 수: 2
Infinite_king
2024년 5월 28일
Hi Syed Adil Ahmed, can you share the code snippet and the output that you are getting ?
채택된 답변
Chunru
2024년 5월 28일
Use "shading interp"
[xq, yq] = meshgrid(linspace(-4, 0, 10), linspace(-0.5, 15, 10));
% Interpolate the scattered data to the meshgrid
% zq = fittedmodel(xq,yq); % Fitted Model is a cfit object, which fits raw data using Lowess smoothed quadratic model.
%zq = exp(-(xq-2).^2-(yq-3).^2); % data
zq = peaks(xq+2, yq-6)
figure(4)
% surface plot
surf(xq, yq, zq);
shading interp
% labels
%zlim([0 5]);
xticks(-[4 3.5 3 2.5 2 1.5 1 0.5 0 -0.5])
yticks([0 2.5 5 7.5 10 12.5 15])
% coloring the colorbar same as reference
% Range values and corresponding colors
ranges = [1 1.5, 2, 2.5, 3, 3.5];
colors = [0, 1, 1; % aqua
0, 0.87, 0.5; % turquoise green
0, 0.5, 0; % green
1, 1, 0; % yellow
1, 0.5, 0; % orange
1, 0, 0;
]; % red
% Colormap definition
colormap(interp1(ranges(1:end), colors, linspace(ranges(1), ranges(end), 6)));
colorbar;
댓글 수: 3
Voss
2024년 5월 28일
[xq, yq] = meshgrid(linspace(-4, 0, 10), linspace(-0.5, 15, 10));
% Interpolate the scattered data to the meshgrid
% zq = fittedmodel(xq,yq); % Fitted Model is a cfit object, which fits raw data using Lowess smoothed quadratic model.
%zq = exp(-(xq-2).^2-(yq-3).^2); % data
zq = peaks(xq+2, yq-6)
figure(4)
% surface plot
surf(xq, yq, zq, 'FaceColor', 'interp');
% labels
%zlim([0 5]);
xticks(-[4 3.5 3 2.5 2 1.5 1 0.5 0 -0.5])
yticks([0 2.5 5 7.5 10 12.5 15])
% coloring the colorbar same as reference
% Range values and corresponding colors
ranges = [1 1.5, 2, 2.5, 3, 3.5];
colors = [0, 1, 1; % aqua
0, 0.87, 0.5; % turquoise green
0, 0.5, 0; % green
1, 1, 0; % yellow
1, 0.5, 0; % orange
1, 0, 0;
]; % red
% Colormap definition
colormap(interp1(ranges(1:end), colors, linspace(ranges(1), ranges(end), 6)));
colorbar;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!