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

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

 Akzeptierte Antwort

Jan
Jan am 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.

3 Kommentare

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
colormap(hAxesP,gray);
%plot pcolor for gradient
pcolorPlot = pcolor(X,Y,Zprime);
set(pcolorPlot,'FaceColor','interp','EdgeColor','interp');
%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
axis(hAxesCM,'off')
%set colormap for contourm axes
colormap(hAxesCM,cool);
%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
linkaxes([hAxesP,hAxesCM]);
When I use my mouse to rotate the plots, only one is rotated (the one I grabbed)
I solved it with
linkprop([ax2 ax1], {'View', 'XLim', 'YLim', 'ZLim'})
Thanks :)
This was very helpful, thank you Fabian and Jan!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017b

Gefragt:

am 6 Aug. 2018

Bearbeitet:

am 9 Mär. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by