Modify Surface plot display format
5 次查看(过去 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?
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!