How to add another colorbar/colormap for two different pointclouds that are plotted together with pcshow?
12 views (last 30 days)
Show older comments
I was able to overlay two different pointclouds on a single plot using:
pcshow(pointcloud1); hold on; pcshow(pointcloud2)
These two pointclouds have different intensity ranges (e.g. 1 pointcloud intensity range is 1-100, while the other is 20-40), therefore it would make sense to have two distinct colorbars and colormaps for each respective pointcloud.
I understand that this can be done using scatter3 and link both axes (like shown and answered in: https://www.mathworks.com/matlabcentral/answers/194554-how-can-i-use-and-display-two-different-colormaps-on-the-same-figure) and I have done this before with scatter3. However, scatter3 does not work for my application as my dataset is very large and is very slow, while pcshow works well, loads quickly, and is manageable.
Hopefully there is a solution and if not I would like to hear some alternatives for this. Thanks
0 Comments
Accepted Answer
Narvik
on 29 Aug 2023
Hi,
You can accomplish this by utilizing the "linkprop" function to link the axes' properties after plotting the point clouds on different axes.
For more information on the “linkprop” function, you can refer to the following documentation:
Please find the working code below :
% Generate a unit sphere with 100 faces.
[x,y,z] = sphere(100);
% Generate an ellisoid with 100 faces.
[X,Y,Z] = ellipsoid(0,0,0,0.25,0.25,0.5,100);
figure;
%%% Point cloud for the sphere %%%
% Not including the below statement may
% lead to unexpected behaviour. Try to
% comment the below line and check for youself.
ax1 = axes;
% Using pcshow to plot 3D point cloud of sphere.
ax1 = pcshow([x(:) y(:) z(:)]);
%%% Point cloud for the ellipsoid %%%
% Not including the below statement may
% lead to unexpected behaviour. Try to
% comment the below line and check for youself.
ax2 = axes;
% Using pcshow to plot 3D point cloud of ellipsoid.
ax2 = pcshow([X(:) Y(:) Z(:)]);
% Link the two axes together.
% Change the properties based on your use case.
hlink = linkprop([ax1, ax2], {'CameraUpVector','CameraPosition','CameraTarget'});
% Hiding the top axes.
ax2.Visible = 'off';
ax2.XTick = [];
ax2.YTick = [];
% Adding colormap for each of the point clouds.
colormap(ax1, 'hot');
colormap(ax2, 'winter');
% Adding colobar at specific positions.
% The four-element vector position specifies [left bottom width height].
cb1 = colorbar(ax1,'Position',[0.1 0.1 0.05 0.81]);
cb2 = colorbar(ax2,'Position',[0.85 0.1 0.05 0.81]);
% Changing text color to white (black background)
cb1.Color = 'w';
cb2.Color = 'w';
The output of the code is as follows :
Hope this helps!
More Answers (0)
See Also
Categories
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!