MATLAB Answers

How do I link/lock multiple axis so that they all rotate simultaneously?

66 views (last 30 days)
Fabian Gock
Fabian Gock on 6 Aug 2018
Commented: M Carpenter on 20 May 2019
I have two sets of axis in one figure and I want to use my mouse to 3D-rotate the plots. The Axis are aligned using linkaxes() and ax1.Position = ax2.Position
The problem is, that only one plot is rotating at a time.
I used two axis, because I want a different colormap on each one.
Thanks for any suggestions! -Fabian


Sign in to comment.

Accepted Answer

Jan on 6 Aug 2018
The 'Position' property is the location relative to the figure. But you want to control the 'CameraPosition', 'CameraTarget', 'CameraUpVector' and 'CameraViewAngle'. Use linkaxes to link them.


Fabian Gock
Fabian Gock on 6 Aug 2018
I already called linkaxes.
See this example:
%create data
[X,Y,Z] = peaks(30);
Zprime = del2(Z);
contourmin = min(Z(:));
contourmax = max(Z(:));
pcolormin = min(Zprime(:));
pcolormax = max(Zprime(:));
%create figure and store handle
hF = figure;
%create axes for pcolor and store handle
hAxesP = axes;
%set colormap for pcolor axes
%plot pcolor for gradient
pcolorPlot = pcolor(X,Y,Zprime);
%create color bar and set range for color
cbP = colorbar(hAxesP,'Location','west');
caxis(hAxesP,[pcolormin pcolormax]);
%create axes for the countourm axes
hAxesCM = axes;
%set visibility for axes to 'off' so it appears transparent
%set colormap for contourm axes
%plot contourm
contourmPlot = contourm(X,Y,Z,20);
%create color bar and set range for color
cbCM = colorbar(hAxesCM,'Location','east');
caxis(hAxesCM,[contourmin contourmax]);
%link the two overlaying axes so they match at all times to remain accurate
When I use my mouse to rotate the plots, only one is rotated (the one I grabbed)
Fabian Gock
Fabian Gock on 6 Aug 2018
I solved it with
linkprop([ax2 ax1], {'View', 'XLim', 'YLim', 'ZLim',})
Thanks :)

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!

Translated by