Plot of 3D colour scatter graph

3 ビュー (過去 30 日間)
Nicholas Omoding
Nicholas Omoding 2021 年 7 月 4 日
コメント済み: Scott MacKenzie 2021 年 7 月 10 日
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'
  1 件のコメント
Nicholas Omoding
Nicholas Omoding 2021 年 7 月 10 日
Thanks for the response. Please kindly see the subset of my data attached.

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


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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by