Torsten Schönfeld
Torsten Schönfeld

Reputation: 108

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?

Upvotes: 5

Views: 701

Answers (1)

Hugh Nolan
Hugh Nolan

Reputation: 2519

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');

Upvotes: 2

Related Questions