Scatter point plot into plot3d or any surface

Answers (2)
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!
0 Comments
0 Comments
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!