Smoothing 3D surface plot and its color gradient
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hariharan Siva
el 6 de Sept. de 2023
Comentada: Star Strider
el 6 de Sept. de 2023
I am currently facing trouble replicating the attached figure.

In specific, I am facing difficulties in achieving a seamless 3D surface plot, as well as its transitioning from discrete to continuous color gradients. In my efforts to smooth the surface, I have tried with increasing the data point density and interpolations to enhance its smoothness. But it yielded a somewhat jagged effect. Same goes to the color scale.
Any assistance in resolving these issues would be highly appreciated.
filename = 'Data.csv';
data = readmatrix(filename);
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
% Create a mesh grid for X and Y
[X, Y] = meshgrid(x, y);
% Create a mesh grid for Z
Z = meshgrid(z);
% Add a vertical line at z = 0 by making a mesh grid
Z0 = zeros(size(X));
% 3D surface plot
figure;
set(gcf, 'Color', [1, 1, 1]);
surf(X, Y, Z, 'EdgeColor', 'none');
lineColors = [...
90, 0, 9
120, 25, 7
157, 56, 10
187, 97, 45
202, 129, 88
216, 163, 131
231, 198, 179
255, 255, 255
191, 215, 227
132, 180, 203
75, 143, 180
25, 107, 154
3, 75, 133
2, 47, 115
1, 18, 98
]./255;
vik = interp1(1:max(size(lineColors)),lineColors,1:(1/4):max(length(lineColors)));
colormap(flipud(vik));
% colorbar;
caxis([-0.6, 1]);
% X-axis limits to match data
xlim([min(x), max(x)]);
ylim([-2, 2]);
hold on;
% Add a grey section
surf(X, Y, Z0, 'EdgeColor', 'none', 'FaceColor', [0.5, 0.5, 0.5], 'FaceAlpha', 0.2);
hold off;
% Remove gridlines, axis labels, and tick marks for y and z axes
grid off;
set(gca, 'YTick', []);
set(gca, 'ZTick', []);
set(gca, 'YColor', 'none');
set(gca, 'ZColor', 'none');
grid on;
set(gca, 'GridColor', [0.5, 0.5, 0.5]);
0 comentarios
Respuesta aceptada
Star Strider
el 6 de Sept. de 2023
filename = 'Data.csv';
data = readmatrix(filename);
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
% Create a mesh grid for X and Y
[X, Y] = meshgrid(x, y);
% Create a mesh grid for Z
Z = meshgrid(z);
% Add a vertical line at z = 0 by making a mesh grid
Z0 = zeros(size(X));
% 3D surface plot
figure;
set(gcf, 'Color', [1, 1, 1]);
surf(X, Y, Z, 'EdgeColor', 'none');
lineColors = [...
90, 0, 9
120, 25, 7
157, 56, 10
187, 97, 45
202, 129, 88
216, 163, 131
231, 198, 179
255, 255, 255
191, 215, 227
132, 180, 203
75, 143, 180
25, 107, 154
3, 75, 133
2, 47, 115
1, 18, 98
]./255;
vik = interp1(1:max(size(lineColors)),lineColors,1:(1/4):max(length(lineColors)));
colormap(flipud(vik));
% colorbar;
caxis([-0.6, 1]);
% X-axis limits to match data
xlim([min(x), max(x)]);
ylim([-2, 2]);
hold on;
% Add a grey section
surf(X, Y, Z0, 'EdgeColor', 'none', 'FaceColor', [0.5, 0.5, 0.5], 'FaceAlpha', 0.2);
hold off;
% Remove gridlines, axis labels, and tick marks for y and z axes
grid off;
set(gca, 'YTick', []);
set(gca, 'ZTick', []);
set(gca, 'YColor', 'none');
set(gca, 'ZColor', 'none');
grid on;
set(gca, 'GridColor', [0.5, 0.5, 0.5]);
daspect([10 1 1]) % <— ADDED
It changes the aspect ratio of the plot axes.
.
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
