MATLAB rotate xtick labels
Asked Answered
P

3

5

I cannot figure out how to rotate my xtick labels in a 3d graph. Someone previously suggested:

set(get(gca,'xlabel'), 'Rotation',90)

But when I do this, nothing changes.

The whole code is:

width = 0.7
zheight = 500
set(0,'DefaultAxesLineStyleOrder',{'-*',':','o'})

d=bar3(a,x,width)
set(gcf,'color','w');
zlim([0 zheight])

set(gca,'FontSize',14 ,'FontWeight','bold')
set(gca, 'YTick',1:8, 'YTickLabel',{'1','2','4','8','12','16','20','24'})
set(gca, 'XTick',1:7, 'XTickLabel',{'a' 'b' c' 'd' 'e','f','g'})
set(get(gca,'xlabel'),'rotation',90)
Parasynapsis answered 30/7, 2014 at 20:46 Comment(9)
I think I want xticlabel, not xlabel, but when I do that, I just get:Error using set Conversion to double from cell is not possible. Error in comp_cost (line 13) set(get(gca,'XTickLabel'),'rotation',80)Parasynapsis
Maybe this can help: mathworks.com/matlabcentral/answers/…Koodoo
here is a FEX submission: mathworks.com/matlabcentral/fileexchange/3486-xticklabel-rotate (there are many others)Millford
@Millford If I use this, what do I Add to my script? Every time I Try calling a function like this I just get errors, probably due to me implementing the function incorrectlyParasynapsis
For instance, if I add xticklabel_rotate(XTick,rot,varargin) I get: Undefined function or variable 'XTick'.Parasynapsis
@JacksonHart - There's an example on that FEX page that tells you how to run it. The example is: xticklabel_rotate([1:5],45,{'label_1','label_2','label_3','label_4','label_5'},'interpreter','none'). The first parameter I'm assuming are the locations of each tick. In this case, each tick goes from 1 up to 5. You'll need to change this to accommodate where exactly your ticks are located on the x-axis. The second argument is the angle you want to rotate each label and the third element is a cell array of labels where each cell element is the label you want for each tick.Drowse
@Drowse When I do this, I get:Unexpected MATLAB operator. and i copied it verbatim, so perhaps there must be something missing.Parasynapsis
Where is the unexpected MATLAB operator happening? The command prompt will tell you the exact locationDrowse
@Drowse in the line that i added the code you suggestedParasynapsis
E
4

You can use this Rotating X axis Labels

Example:

rotateXLabels( xlabel, 45 )
Enormous answered 30/7, 2014 at 21:2 Comment(2)
I want to rotate the tic labels, the the axis labelParasynapsis
the file will allow you to rotate the tic labels.. then you can rotate the axis label yourself..Enormous
M
12

As of matlab version R2014b, this is built into matlab. (As noted in the rotateXLabels package from the answer by @lakesh)

You can rotate the labels:

set(gca, 'XTickLabelRotation', 90)
Mcbee answered 24/2, 2016 at 4:55 Comment(0)
E
4

You can use this Rotating X axis Labels

Example:

rotateXLabels( xlabel, 45 )
Enormous answered 30/7, 2014 at 21:2 Comment(2)
I want to rotate the tic labels, the the axis labelParasynapsis
the file will allow you to rotate the tic labels.. then you can rotate the axis label yourself..Enormous
W
1

Starting from R2016b you can do:

xtickangle(angle)
Westberry answered 6/9, 2017 at 9:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.