user1285419
user1285419

Reputation: 2225

about rotating axis label in matlab

I am plotting some 3-dimensional data with matlab's waterfall, I found that if I set the x- or y-label with the buildin xlabel or ylabel command, the orientation of the label will always be horizontal instead of aligning with the axis. Is that any way to make it oriented along the axis? I found in the help that we can use the command

xlabel('label at 45 degree', 'rot', 45)

to specify the angle of orientation but if I rotate the 3D axis manually, the label won't change accordingly, anyway to fix that? Thanks.

Upvotes: 4

Views: 27512

Answers (1)

angainor
angainor

Reputation: 11810

You can not do it automatically. You have to replace the tic labels/X label with text object and rotate it yourself (see here to know how to do it). Simple solution looks as follows:

plot(1:100);

% make the axis smaller
pos = get(gca, 'Position');
set(gca,'Position',[pos(1), .2, pos(3) 0.7]);

% place custom text instead of xlabel
% note that the position is relative to your X/Y axis values
t = text(50, -5, {'X-axis' 'label'}, 'FontSize', 14);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
'Rotation',45);

Have also a look at this FEX contribution.

Upvotes: 4

Related Questions