Rotate axes labels to align with axes angle in surfaces

75 Ansichten (letzte 30 Tage)
A
A am 2 Jan. 2015
Bearbeitet: Geoff Hayes am 11 Apr. 2016
Hi there,
I have the following example surface:
figure(1)
surf(peaks)
xlabel('X Axis')
ylabel('Y Axis')
zlabel('Z Axis')
How can I 'rotate' the x and y axes labels so that are perfectly aligned with the x and y axes angles, respectively?
I know that I can use something like the below, but I have to play around quite a bit to align it right and even then it doesn't feel like I have the angle correct. Is there a way to "get" the angle of the axes, and then simply use that value in the below code?
surf(peaks)
xlabel('X Axis')
ylabel('Y Axis')
zlabel('Z Axis')
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1,1],'Rotation',11)
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[1,1,1],'Rotation',-11)
zh = get(gca,'ZLabel'); % Handle of the z label
set(zh, 'Units', 'Normalized')
pos = get(zh, 'Position');
set(zh, 'Position',pos.*[1,1,0],'Rotation',90)
Also, it the labels don't 'update' their angle once you rotate the surface once it is generated.
Thank you
  3 Kommentare
A
A am 2 Jan. 2015
Thanks - so when I do that, I then use those angles gives by azimuth into my rotation function, I don't think my labels are aligned?
surf(peaks)
xlabel('X Axis')
ylabel('Y Axis')
zlabel('Z Axis')
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1,1],'Rotation',30)
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[1,1,1],'Rotation',-37.5)
zh = get(gca,'ZLabel'); % Handle of the z label
set(zh, 'Units', 'Normalized')
pos = get(zh, 'Position');
set(zh, 'Position',pos.*[1,1,0],'Rotation',90)
Geoff Hayes
Geoff Hayes am 3 Jan. 2015
No, the azimuth angle does not seem to give the correct alignment for the axes labels. You may have to modify it to get something closer to what you expect.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Nicholas Fette
Nicholas Fette am 11 Apr. 2016
Bearbeitet: Geoff Hayes am 11 Apr. 2016
When your commercial software doesn't do it for you, somebody else does. Did you know that matplotlib aligns labels by default? Or try this http://www.mathworks.com/matlabcentral/fileexchange/49542-tools-for-axis-label-alignment-in-3d-plot.

Community Treasure Hunt

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

Start Hunting!

Translated by