Xtick label alignment in bar plot
35 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am having problem with the xticks in the bar plot. I would like to align the label names along the horizontal line. I am unable to figure out the solution. Any help is greatly appreciated.
A = [30, 10, 7, 4, 4, 3, 2].';
figure(1);
set(gcf,'color','w');
x = (1:size(A,1)).';
myplot = bar(A, 'stacked');
Variables = char('First', 'Second', 'Third',...
'Fourht', 'Large Name', 'Very Large Name', 'Small Name');
t= text(x+.3,0*ones(1,size(x,1)),Variables(1:size(A,1),:));
set(gca,'XTickLabel','');
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
'Rotation',45, 'Fontsize', 13);
ylabel('Contributor %', 'Fontsize', 13);
set(gca, 'OuterPosition', [0.02 0.2 1 0.8]);
0 Kommentare
Akzeptierte Antwort
dpb
am 23 Jun. 2016
Variables = char('First', 'Second', 'Third',...
'Fourth', 'Large Name', 'Very Large Name', 'Small Name');
causes the strings to be appended with blanks to the same length; hence your strings are all the same length and the 'horizontalalignment','right' looks funky compared to what you're expecting.
The fix is use cellstrings instead...
Variables = {'First','Second','Third','Fourth','Large Name','Very Large Name','Small Name'}.';
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Bar Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!