Modify Surface plot display format
6 views (last 30 days)
Show older comments
Syed Adil Ahmed
on 28 May 2024
Commented: Syed Adil Ahmed
on 28 May 2024
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 Comments
Infinite_king
on 28 May 2024
Hi Syed Adil Ahmed, can you share the code snippet and the output that you are getting ?
Accepted Answer
Chunru
on 28 May 2024
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 Comments
Voss
on 28 May 2024
[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;
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!