How to add another colorbar/colormap for two different pointclouds that are plotted together with pcshow?

11 次查看(过去 30 天)
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

采纳的回答

Narvik
Narvik 2023-8-29
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!
  1 个评论
Rendhy Sapiie
Rendhy Sapiie 2023-9-1
This is absolutely great! Exactly what I was looking for and I got it wrong by using linkaxes, but not linkprop! Makes much more sense now. Thank you so much for the detailed answer!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by