假设我有两个相同大小的二维矩阵,并为每个矩阵创建一个表面图。
是否有一种方法可以链接两个图的轴,使得可以同时以相同方向进行三维旋转?
使用linkprop
函数可以同步相机位置属性,这是一种解决方案,但可能不是最高效的方法,与使用ActionPostCallback
和ActionPreCallback
相比。
linkprop([h(1) h(2)], 'CameraPosition'); %h is the axes handle
linkprop
可以同步两个或多个 axes
(2D 或 3D)的任何图形属性。它可以被视为 linkaxes
函数的扩展,后者适用于 2D 绘图并仅同步 axes
的限制。在这里,我们可以使用 linkprop
来同步相机位置属性 CameraPosition
,当旋转一个 axes
时修改该属性。% DATA
[X,Y] = meshgrid(-8:.5:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z1 = sin(R)./R;
Z2 = sin(R);
% FIGURE
figure;
hax(1) = subplot(1,2,1); %give the first axes a handle
surf(Z1);
hax(2) = subplot(1,2,2); %give the second axes a handle
surf(Z2)
% synchronize the camera position
linkprop(hax, 'CameraPosition');
graph_props = fieldnames(get(gca));
linkprop([h(1) h(2)], 'View');
比 'CameraPosition'
更好用。 - ESalaView
比CameraPosition
更好在哪里?CameraPosition
不够强大吗? - chessofnerdView
更加一致。使用CameraPosition
时,当您与其中一个坐标轴的角度很小时,会出现某种捕捉效果。 - Erikfunction syncPlots(A, B)
% A and B are two matrices that will be passed to surf()
s1 = subplot(1, 2, 1);
surf(A);
r1 = rotate3d;
s2 = subplot(1, 2, 2);
surf(B);
r2 = rotate3d;
function sync_callback(~, evd)
% Get view property of the plot that changed
newView = get(evd.Axes,'View');
% Synchronize View property of both plots
set(s1, 'View', newView);
set(s2, 'View', newView);
end
% Register Callbacks
set(r1,'ActionPostCallback',@sync_callback);
set(r1,'ActionPreCallback',@sync_callback);
set(r2,'ActionPostCallback',@sync_callback);
set(r2,'ActionPreCallback',@sync_callback);
end
surf(A); hold on; surf(B);
?这将把两个图形添加到同一个坐标系中。您想要有两个坐标系吗? - umlum