How to link 2 3D subplots to sync zoom and pan?

조회 수: 93 (최근 30일)
Jian Zhou
Jian Zhou 2017년 8월 4일
댓글: matta gopi raju 2020년 7월 23일
Hey every one,
I am trying to link two 3D subplots such that when I rotate, pan or zoom on one of the subplot, the other one will automatically sync to the changed new camera view and axis limits. I came across this solution for syncing camera view when rotating: https://de.mathworks.com/matlabcentral/answers/12171-how-to-link-cameras-for-two-subplots-in-a-single-figure
Using the above solution, rotations can be synced. But when I try to zoom in on one of the subplots, the other subplot doesn't stay on the same position in the figure, it moves around. The same also happpens, when I try to pan one subplot. And when zooming in, the other subplot doesn't sync it's axes limits.
For 2D subplots, linkaxes seems to do the job. So what is the solution for the 3D case?
Below is a example code to illustrate the problem
ax1 = subplot(1, 2, 1);
[x,y,z] = peaks;
surf(x,y,z);
ax2 = subplot(1, 2, 2);
[x,y,z] = peaks(10);
surf(x,y,z);
Link = linkprop([ax1, ax2],{'CameraUpVector', 'CameraPosition', 'CameraTarget'});
setappdata(gcf, 'StoreTheLink', Link);
Any help will be appreciated.
  댓글 수: 3
Jian Zhou
Jian Zhou 2017년 8월 6일
The 2 plots consists of different information of points in 3d space. First one is a point cloud scatter3 plot. Since it is hard to visualize the surface of the 3d point cloud, i plotted its convex hull on the second one to help me judge the 3d point cloud better. Therefore, it is essential for both plots be share a common camera view angle. Thanks for your reply, I tried it, sadly, it doesn't solve the problem.
Adam
Adam 2017년 8월 7일
Try taking a look at both axes handles after you have rotated and see what is different between the two. I can't remember all the properties that affect cameras and view directions, but you ought to be able to see which settings are different. Also a screenshot might help someone suggest what might be going wrong.

댓글을 달려면 로그인하십시오.

채택된 답변

Christopher Creutzig
Christopher Creutzig 2017년 8월 7일
As Adam suggested in the comments, this seems to work:
ax1 = subplot(1, 2, 1);
[x,y,z] = peaks;
surf(x,y,z);
ax2 = subplot(1, 2, 2);
[x,y,z] = peaks(10);
surf(x,y,z);
Link = linkprop([ax1, ax2],{'CameraUpVector', 'CameraPosition', 'CameraTarget', 'XLim', 'YLim', 'ZLim'});
setappdata(gcf, 'StoreTheLink', Link);
  댓글 수: 2
KAE
KAE 2020년 2월 6일
편집: KAE 2020년 2월 6일
Here is a generalized version that will work with any number of axes,
function axList = connectaxes2(axList)
% C:\Users\KEdwards\OneDrive - datacolor\matlab_programs\graphics\
% connectaxes2.m
%
% DESCRIPTION
% Set different 3D axes to the same limits and view angle as you zoom and pan
% INPUT
% axList - List of handles to axes to connct
if nargin == 0 % Pick all open axes, if specific axes are not passed in
axList = findobj('type', 'axes');
end
Link = linkprop(axList,{'CameraUpVector', 'CameraPosition', ...
'CameraTarget', 'XLim', 'YLim', 'ZLim'});
setappdata(gcf, 'StoreTheLink', Link);
matta gopi raju
matta gopi raju 2020년 7월 23일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by