x axis text overlapping in matlab

2.9k views Asked by At

My x axis text are overlapping. I am using this code--

   clear all
   A=[1 2 3 4 5 6 7]';
 b=1:length(A);
 figure(1)
 bar(A)
 title('Loss Diagram')
 xlabel('Loss factor')
 ylabel('kWh/year','fontsiz`enter code here`e',20)
 grid on

set(gca,'Xtick',b,'XtickLabel',{'Horizntl Global Irr. ' 'Effective irr. on coll. ' 'Array nominal energy ' 'PV module loss ' 'charge controller loss  ' 'Battery efficiency loss ' 'converter loss '},'fontsize',14);

![matlab image]http://filepi.com/i/HeQt8pE

1

There are 1 answers

2
ulima2_ On BEST ANSWER

You didn't ask a question, but I assume you want some way of displaying your x-axis labels without overlapping.

A solution is rotateXLabels.m, which is also build into the newest Matlab versions.

Here's an example:

A=[1 2 3 4 5 6 7]';
b=1:length(A);

figure(1)
bar(A)

title('Loss Diagram')
xlabel('Loss factor')
ylabel('kWh/year', 'FontSize', 20)
grid on

set(gca,'Xtick',b,'XtickLabel', ...
    {'Horizntl Global Irr. ', 'Effective irr. on coll. ', ...
    'Array nominal energy ' 'PV module loss ' 'charge controller loss ', ...
    'Battery efficiency loss ' 'converter loss '}, 'FontSize', 14);

rotateXLabels( gca(), 45 )

Which produces: enter image description here