同じサイズの 2 つの 2 次元行列があり、それぞれの表面プロットを作成するとします。
両方のプロットの軸をリンクして、両方を同時に同じ方向に 3D 回転できるようにする方法はありますか?
5908 次
2 に答える
14
ActionPostCallback
andで遊ぶActionPreCallback
ことは確かに解決策ですが、おそらく最も効率的なものではありません。関数を使用linkprop
して、カメラの位置プロパティを同期できます。
linkprop([h(1) h(2)], 'CameraPosition'); %h is the axes handle
linkprop
2 つ以上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));
于 2013-09-12T14:53:26.207 に答える
5
1 つの方法は、回転イベントでコールバックを登録し、両方の軸で新しい状態を同期することです。
function 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
于 2013-09-12T13:34:30.410 に答える