MATLAB Answers

0

Plotting a patch hides all scatter data in figure

Asked by Kevin Mohr on 10 Oct 2019
Latest activity Edited by Adam Danz
on 11 Oct 2019
I am trying to plot cubes (really just groups of patches using the function found here: https://www.mathworks.com/matlabcentral/fileexchange/15161-plotcube ) as well as 3D scatter data on the same plot. However, every time a patch is rendered on the figure, it hides all scatter data. I have tried reordering the creation of the objects in order to have the scatter data be shown, forcing the scatter data to the top using uistack(scatterObj,'top'), and messing with the rendering options to no avail.
The following code is a simplified version of what I am trying to do in the end, but it demonstrates the issue. My questions are:
Is there some property of patches that I have not yet found that causes this behavior?
Is there a better way of rendering these rectangles?
Is there some inherent issue with the way that I am trying to acheive this functionality?
% scatterData =
%
% X: [1x4096 double]
% Y: [1x4096 double]
% Z: [1x4096 double]
% C: [1x4096 double]
%
% cubeData =
%
% Edges: [8.6500 1.5900 2.3200]
% Origin: [4.7000 -18.7500 0]
% Alpha: 0.1000
% Colors: [0.0596 0.6596 0.1734]
close all
figure()
scatterObj = scatter3(scatterData.X,scatterData.Y,scatterData.Z,0.5,scatterData.C)
hold on
plotcube(cubeData.Edges,cubeData.Origin,cubeData.Alpha,cubeData.Colors)
xlim([-50 50])
ylim([-50 50])
zlim([-10 10])

  0 Comments

Sign in to comment.

1 Answer

Answer by Adam Danz
on 10 Oct 2019
Edited by Adam Danz
on 10 Oct 2019
 Accepted Answer

Works for me (see below). The marker size in your question is quite small (0.5) but with 4096 points, you should see something. The markesize below is 30, for comparison. Unlike other markers, scatter dot size units are points-squared. The size property is an area of points.
Have you tried restarting matlab? Have you tried setting the alpha value in plotcube() to 1.0 so that there is no transparency? If the probelm persist, what is the value of info = rendererinfo(gca) where gca is the handle to your axes?
figure()
scatterObj = scatter3(rand(1,30),rand(1,30),rand(1,30),50,rand(30,3),'MarkerFaceColor', 'flat')
hold on
plotcube([.5 .5 .5],[.2 .2 .2],0.1,[0 0 1])

  3 Comments

Even if I use data that resembles what you described in the question, it still works, as long as the marker size is big enough to see. The markersize below is 2.
figure()
scatterObj = scatter3(rand(1,4096)*100-50,rand(1,4096)*100-50,rand(1,4096)*20-10,2,rand(4096,3),'MarkerFaceColor', 'flat')
hold on
plotcube([8.6500 1.5900 2.3200],[4.7000 -18.7500 0],0.1,[0.0596 0.6596 0.1734])
xlim([-50 50])
ylim([-50 50])
zlim([-10 10])
191010 194005-Figure 1.png
Here's another run with 0.5 markersize
191010 194125-Figure 1.png
Thank you for your feedback. Increasing the marker size worked for me as well. Even a value as small as 1 still shows the points.
Good!
The lesson is that scatter uses different units than the other plotting markersize properties.
Scatter units are an area in points squared.
Plot units are linear in points (not squared) where 1 point is 1/72 of an inch.
So, to equate the plot markersize with scatter markersize,
sqrt(plotMarkerSize) = scatterMarkerSize
plotMarkerSize = scatterMarkerSize^2
191010 200427-Figure 1.png

Sign in to comment.