Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perspective issue with scatter3 in MATLAB R2011b

I'm seeing a perspective issue with three-dimensional scatter plots: some points are drawn over points which should be in front of them in the current projection. Example with a sampled cylinder:

[r, phi, h] = meshgrid(1, 0:pi/10:2*pi, 0:0.05:1);
x = r.*cos(phi);
y = r.*sin(phi);
z = h;
xyz = [x(:) y(:) z(:)];
scatter3(xyz(:,1), xyz(:,2), xyz(:,3), 50, xyz(:,3), 'filled')
view(-37, 28)

Notice how some of the blue-ish dots from the back are drawn over the red-ish dots from the front. The issue is not present in PNG exports of the figure, so there is no point in providing an image.

So, why is this happening? Does it depend on the order of the points in the x, y, z vectors? Has it been fixed in newer releases?

like image 447
Torsten Schönfeld Avatar asked Nov 03 '22 19:11

Torsten Schönfeld


1 Answers

This is an error with the default renderer painters. It is not fixed in 2012b, I haven't downloaded 2013a yet.

You can change the figure renderer to zbuffer or opengl to fix:

set(gcf,'renderer','zbuffer');
set(gcf,'renderer','opengl');
like image 182
Hugh Nolan Avatar answered Nov 08 '22 09:11

Hugh Nolan