MATLAB: 3D point clouds with variable marker transparency, color and size

3d plottingmarkerhandleMATLABplot3point clouds

I would like to make 3D point clouds in which the markers have variable color, transparency and/or marker size. I would like to do this in one function call, because it seems like Matlab can have some strange occlusion issues if multiple point-clouds are combined via a loop and the viewpoint is changed.
I have tried using the hidden MarkerHandle settings as described here and it works brilliantly with the exception that transparency is only binary for markers of the '.' type (i.e. the only alpha value that affects the graph is 0, in which case the point is un-rendered), unless the marker size is > 15, in which it seems that a different openGL primitive may be used. To get small points with variable transparency one can use e.g. 'o', and set EdgeColorType/Binding/Data and FaceColorType/Binding/Data appropriately.
In both cases, however, if the number of points >25,000 then rotating, zooming or scaling the figure resets the marker handles on-the-fly which makes it impossible to interact with the point cloud while maintaining the custom markerhandle settings.
Variable markersize could function as an alternative to transparency but I don't see how to do that with a single function call, and in any case the marker handle resetting still causes problems for interactive data exploration for large point clouds. Any pointers on how to accomplish this?

Best Answer

"I would like to make 3D point clouds in which the markers have variable color, transparency and/or marker size. "
I suggest using scatter3() where marker size and marker color can be set for each individual point. Here's a demo that creates a 3D volume of 30k points with varying colors and marker sizes that are defined by the depth of each point along the z-axis. The transparency of all points are set to 0.5.
% Create data (30k 3D points)
n = 30000;
x = rand(1,n)*100;
y = rand(1,n)*100;
z = rand(1,n)*100;
% Define color of each point based on z value
colors = jet(numel(z));
[~, ~, depthIdx] = unique(abs(z));
colorData = colors(depthIdx,:);
% Define size gradient based on z value
dotSize = linspace(10,100,numel(x));
sizeData = dotSize(depthIdx);
% Plot 3D points
scatter3(x,y,z,sizeData,colorData,'filled','o','MarkerEdgeColor','k', ...
'MarkerFaceAlpha',0.5);
grid on
box on
xlabel('x')
ylabel('y')
zlabel('z')
% Choose your viewing angle:
view(0,180) % (x,z) view
view(2) % (x,y) view
view(3) % (x,y,z) view
191224 060821-Figure 1.png