MATLAB Answers


Synchronise different viewing angles onto same scatter plot

Asked by Lukas Kortmann on 2 Sep 2016
Latest activity Commented on by Lukas Kortmann on 5 Sep 2016
I'm trying to have a figure with two subplots (or preferably even two separate figures), showing the same 3d point cloud, but from different viewing angles. I would like to see the same point cloud from two different angles to get a better feeling for the points' locations in the 3d space, and I must be able to rotate the plots in sync. I managed to have 2 plots synchronised using linkprop, but I can't change the angle of one of the plots once they're synced.
Thanks for any help!


The rotate tool changes view() which in turn changes the axes CameraPosition and CameraViewAngle . Considering that you want different viewing angles, exactly what is it that you want to be synchronized between the two? CameraPosition, CameraViewAngle, CameraTarget, CameraUpVector ?
In terms of view, if the first plot is
then what should be the view() for the second plot?
I want to have the view synchronised. If the first plot was
then I would like the second one to be something like
Sorry for my late reply, but I didn't see that only answers, not comments, would get email notifications.

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 5 Sep 2016
 Accepted Answer

You will need to use addlistener for changes to the CameraPosition and CameraViewAngle properties . In the listener, you can call view() on the first axis to find the values that you would then add 20 to and call view() for the second axes.
linkprop and linkaxes are only for synchronizing exact values, and do not provide for computing one property based upon the other.


Ok, so I tried
f1 = figure;
sc1 = scatter3(1,1,1,'r+');
h1 = addlistener(gca, 'CameraViewAngle','PostSet',@viewChangedCallback)
(only one figure, so gca points to the right one) with a callback function
function viewChangedCallback()
But nothing happens when I rotate the view. Am I on the right track?
Okay, it appears that you can addlistener on 'View', at least in R2016a.
Awesome, that works. Thanks!
If someone else has the same problem, here is a minimum working example:
f1 = figure;
sc1 = scatter3(1,1,1,'r+');
sc2 = scatter3(1,1,1,'g+');
lh1 = addlistener(gca, 'View','PostSet',@viewChangedCallback)
and the callback function:
function viewChangedCallback(src,evt)
[az, el] = view(gca);
view(gca, az+20, el+20);
For robustness, gca should be replaced with fixed references.

Sign in to comment.