Plot of 3D colour scatter graph

4 次查看(过去 30 天)
Hello,
I have a 3D data set of surface erosion for over 700,000 points, and this is tabulated in the form (x, y, z, D). That is, for each 3D point (x, y, z), there is a corresponding value of surface erosion suffered (D)?
Please could someone assist me to visualise this data such that erosion depth controls the colour.
Thanks.
  2 个评论
Scott MacKenzie
Scott MacKenzie 2021-7-4
What is z in your data set? Perhaps post a subset of your data.
Nicholas Omoding
Nicholas Omoding 2021-7-10
Z is the elevation of the points whilst erosion (relative change at each point is denoted by D). Please see the attached sub-set of the data.

请先登录,再进行评论。

采纳的回答

Scott MacKenzie
Scott MacKenzie 2021-7-10
编辑:Scott MacKenzie 2021-7-10
I think this is more or less what you're after:
f = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/679873/point_erosion.xlsx';
M = readmatrix(f);
x = M(:,1);
y = M(:,2);
z = M(:,3);
D = M(:,4);
N = 250; % faster with downsampling; looks the same
xv = linspace(min(x), max(x), N);
yv = linspace(min(y), max(y), N);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym);
Dm = griddata(x, y, D, Xm, Ym);
surf(xv,yv,Zm,Dm, 'edgecolor', 'none');
xlabel('X'); ylabel('Y'); zlabel('Z');
cb = colorbar;
cb.Label.String = 'Erosion';
cb.Label.FontSize = 12;
  5 个评论
Scott MacKenzie
Scott MacKenzie 2021-7-10
Ok, very interesting. Thanks for this explanation. Good luck with your research.
Scott MacKenzie
Scott MacKenzie 2021-7-10
@Nicholas Omoding Just one final thought. You probably want to add a colorbar to the graph, to reveal what the color data represent. I just tweaked my answer to include this.

请先登录,再进行评论。

更多回答(2 个)

Image Analyst
Image Analyst 2021-7-4
编辑:Image Analyst 2021-7-4
Is this what you want?
% Scatter3 demo where marker color and size varies according to data value.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
% Create sample data.
numPoints = 300;
x = rand(1, numPoints); % Coordinates
y = rand(1, numPoints);
z = rand(1, numPoints);
maxDataValue = 1000; % Whatever you want the most extreme color to represent.
minDataValue = -200; % Whatever you want the most extreme color to represent.
D = minDataValue + (maxDataValue - minDataValue) * rand(1, numPoints); % Data values might not ever reach minDataValue or maxDataValue
% Define a colormap
numColors = 256;
cmap = jet(numColors);
%=====================================================================================================================
% Demo #1 : Vary size and color according to magnitude of data.
% Get the index (color) for each of the D values
DScaled = (D - minDataValue) / (maxDataValue - minDataValue);
colorIndexes = ceil(numColors * DScaled);
colors = cmap(colorIndexes, :);
% Scale marker sizes so that bigger values get bigger markers.
sizes = rescale(D, 50, 150);
subplot(1, 2, 1);
scatter3(x, y, z, sizes, colors, 'filled');
grid on;
axis equal;
colormap(cmap);
colorbar;
caxis([0, maxDataValue])
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
title('Marker Color and Size Varied According to Data Value', 'FontSize', fontSize);
%=====================================================================================================================
% Demo #2 : Vary size and color according to distance of data from origin.
distances = sqrt(x.^2 + y.^2 + z.^2);
maxDistanceValue = sqrt(3);
% Get the index (color) for each of the D values
DScaled = distances / maxDistanceValue;
colorIndexes = ceil(numColors * DScaled);
colors = cmap(colorIndexes, :);
% Scale marker sizes so that bigger values get bigger markers.
sizes = rescale(D, 50, 150);
subplot(1, 2, 2);
scatter3(x, y, z, sizes, colors, 'filled');
grid on;
axis equal;
colormap(cmap);
colorbar;
caxis([0, maxDistanceValue])
xlabel('x', 'FontSize', fontSize);
ylabel('y', 'FontSize', fontSize);
zlabel('z', 'FontSize', fontSize);
title('Marker Color and Size Varied According to Distance from Origin', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized'

Max Heiken
Max Heiken 2021-7-4
Since the erosion is specified per vertex, I think scatter3 is to be preferred over surf or mesh.
I would start with something straight-forward like
scatter3(x, y, z, [], D, '.')
cb = colorbar;
ylabel(cb, "erosion")
colormap copper % change for aesthetics
With 700000 points in one plot, performance will be bad, so depending on that you might need to perform some data reduction.
After observing the scatter plot, you can of course decide if another type of plot would be more appropriate.

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by