Modify Surface plot display format

5 ビュー (過去 30 日間)
Syed Adil Ahmed
Syed Adil Ahmed 2024 年 5 月 28 日
コメント済み: Syed Adil Ahmed 2024 年 5 月 28 日
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
Infinite_king 2024 年 5 月 28 日
Hi Syed Adil Ahmed, can you share the code snippet and the output that you are getting ?
Syed Adil Ahmed
Syed Adil Ahmed 2024 年 5 月 28 日
%% Plotting lowess quadratic fitted model at 10x10 discrete points
% grid generated for interpolating surface
[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.
figure(4)
% surface plot
surf(xq, yq, zq);
% 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;
Sure. the code for generating the surface is shown above.
The output is the figure shown in the main question without my paint pencil drawing. The fitted model is a cfit object that I have from some raw data.

サインインしてコメントする。

採用された回答

Chunru
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)
zq = 10x10
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0028 0.0043 -0.0118 -0.0725 -0.1611 -0.1983 -0.1473 -0.0679 -0.0194 -0.0034 0.0561 0.3655 0.7879 -0.0124 -2.9390 -5.2998 -4.2023 -1.4980 -0.0408 0.1540 -1.2288 -2.5906 -2.5708 -0.3293 0.8099 -0.0144 0.9605 2.8957 2.6585 1.2060 0.0715 0.3943 1.3729 3.1035 4.6315 4.6252 3.1306 1.4540 0.4682 0.1052 0.0001 0.0003 0.0010 0.0022 0.0033 0.0033 0.0022 0.0010 0.0003 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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
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)
zq = 10x10
0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 0.0028 0.0043 -0.0118 -0.0725 -0.1611 -0.1983 -0.1473 -0.0679 -0.0194 -0.0034 0.0561 0.3655 0.7879 -0.0124 -2.9390 -5.2998 -4.2023 -1.4980 -0.0408 0.1540 -1.2288 -2.5906 -2.5708 -0.3293 0.8099 -0.0144 0.9605 2.8957 2.6585 1.2060 0.0715 0.3943 1.3729 3.1035 4.6315 4.6252 3.1306 1.4540 0.4682 0.1052 0.0001 0.0003 0.0010 0.0022 0.0033 0.0033 0.0022 0.0010 0.0003 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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;
Syed Adil Ahmed
Syed Adil Ahmed 2024 年 5 月 28 日
Thanks for both replies. Thats exactly what I was looking for. !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by