Scatter point plot into plot3d or any surface

21 visualizaciones (últimos 30 días)
Hugo David
Hugo David el 7 de Sept. de 2025 a las 4:25
Respondida: Star Strider el 7 de Sept. de 2025 a las 12:47
i want to know if i can make a surface based on the following plots. The data in x,y,z are vectors and i want to get some surface (if possible)
  1 comentario
Hugo David
Hugo David el 7 de Sept. de 2025 a las 4:26
Currently iam using the following lines
lbl = sprintf('\\textit{fixed }$\\delta_{lim} = %.1f$', Deep);
plot3(all_puntosh, all_gpIncremento,all_puntosk, '.k', 'DisplayName', lbl);

Iniciar sesión para comentar.

Respuestas (2)

Umar
Umar el 7 de Sept. de 2025 a las 6:07

Hi @Hugo David,

I saw your question about creating a surface from your scattered x,y,z data points. Yes, you can definitely make a surface from your vectors! Here's the best way to do it:

For your current code: You're using

plot3(all_puntosh, all_gpIncremento,all_puntosk, '.k', 'DisplayName', lbl); 

which shows the scatter points, but to get a surface, you need to interpolate between these points.

Here's the solution that works well:

% Create interpolation from your data
F = scatteredInterpolant(all_puntosh, all_gpIncremento, all_puntosk, 'linear');
% Make a regular grid
x_grid = linspace(min(all_puntosh), max(all_puntosh), 40);
y_grid = linspace(min(all_gpIncremento), max(all_gpIncremento), 40);
[X, Y] = meshgrid(x_grid, y_grid);
% Get Z values for the surface
Z = F(X, Y);
% Plot the surface
figure;
surf(X, Y, Z, 'FaceAlpha', 0.7);
hold on;
% Add your original points on top
lbl = sprintf('\\textit{fixed }$\\delta_{lim} = %.1f$', Deep);
plot3(all_puntosh, all_gpIncremento, all_puntosk, '.k', 'MarkerSize', 6);
xlabel('Normalized gain');
ylabel('Normalized rotation frequency'); 
zlabel('Normalized depth of cut');

Why this works: * Takes your scattered points and fills in the gaps to make a smooth surface * Keeps your original data points visible as black dots * Works even if your points aren't arranged in a perfect grid

Quick alternative if you want something simpler:

[X, Y] = meshgrid(linspace(min(all_puntosh), max(all_puntosh), 30), ...
                linspace(min(all_gpIncremento), max(all_gpIncremento), 30));
Z = griddata(all_puntosh, all_gpIncremento, all_puntosk, X, Y);
surf(X, Y, Z);
hold on;
plot3(all_puntosh, all_gpIncremento, all_puntosk, '.k');

Tips * If you have gaps in your data, the surface might look weird in those areas * You can change the grid size (40x40) to make it smoother or faster * Try 'cubic' instead of 'linear' if you want a smoother surface

This should give you the surface plot you're looking for while keeping your scatter points visible.

Let me know if you run into any issues!

Good luck!


Star Strider
Star Strider el 7 de Sept. de 2025 a las 12:47
It would help to have your data.
It might not be necessary to do any interpolation if you only want to use those vectors. Just use the reshape function.
Since there appear to be 4 replicated vectors, one dimension will obviously be 4.
Example --
x = 0:20;
y = 1:4;
[X,Y] = ndgrid(x,y);
Z = exp(-((X-10).^2/5 + (Y-2.5).^2/2.5));
Data = [X(:), Y(:), Z(:)]
Data = 84×3
0 1.0000 0.0000 1.0000 1.0000 0.0000 2.0000 1.0000 0.0000 3.0000 1.0000 0.0000 4.0000 1.0000 0.0003 5.0000 1.0000 0.0027 6.0000 1.0000 0.0166 7.0000 1.0000 0.0672 8.0000 1.0000 0.1827 9.0000 1.0000 0.3329 10.0000 1.0000 0.4066 11.0000 1.0000 0.3329 12.0000 1.0000 0.1827 13.0000 1.0000 0.0672 14.0000 1.0000 0.0166
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
stem3(Data(:,1), Data(:,2), Data(:,3), '.', 'filled')
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''stem3'' Plot Of Original Data')
axis('padded')
colormap(turbo)
Xm = reshape(Data(:,1), [], 4); % Convert Vector To Matrixs Using 'reshape'
Ym = reshape(Data(:,2), [], 4); % Convert Vector To Matrixs Using 'reshape'
Zm = reshape(Data(:,3), [], 4); % Convert Vector To Matrixs Using 'reshape'
figure
surf(Xm, Ym, Zm)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('''surf'' Plot Of Reshaped Vectors')
axis('padded')
colormap(turbo)
Interpolation has its uses, however using reshape is more efficient thaat interpolating if your data are appropriate for it.
.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by