MATLAB rotate xtick labels

15,225

Solution 1

You can use this Rotating X axis Labels

Example:

rotateXLabels( xlabel, 45 )

Solution 2

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)

Solution 3

Starting from R2016b you can do:

xtickangle(angle)
Share:
15,225
Ben
Author by

Ben

Updated on June 07, 2022

Comments

  • Ben
    Ben almost 2 years

    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)
    
  • Ben
    Ben almost 10 years
    I want to rotate the tic labels, the the axis label
  • lakshmen
    lakshmen almost 10 years
    the file will allow you to rotate the tic labels.. then you can rotate the axis label yourself..