How to display all x-labels on 'bar' plot?
matlab, plot
Solution
Add the following line:
set(gca,'XTick',1:numel(publications))
before you set the labels.
Now it depends how big your resulting plot is, because the labels are a little packed. You may adjust fontsize or Orientation or the gaps between the bars.
Probably the publication names are a little longer so a 90° rotation is the best and you may find this answer or this link helpful.
Another suggestion would be to use `barh` and rotate after print:
publications = [15 12 35 12 19 14 21 15 7 16 40 28 6 13 16 6 7 22 23 16 45];
bh = barh(publications,0.4)
set(gca','XAxisLocation','top')
set(gca,'YTick',1:numel(publications))
set(gca,'YTickLabel',{'G1','G2','G3','G4','G5','G6','G7','G8','G9','G10',...
'G11','G12','G14','G16','G17','G18','G19','G20','G21','G22','G23'})
Problem
I have the following data that I wish to plot in a bar graph in MatLab: ``` publications = [15 12 35 12 19 14 21 15 7 16 40 28 6 13 16 6 7 22 23 16 45]; bar(publications,0.4) set(gca,'XTickLabel',{'G1','G2','G3','G4','G5','G6','G7','G8','G9','G10',... 'G11','G12','G14','G16','G17','G18','G19','G20','G21','G22','G23'}) ``` However, when I execute this, I get the following plot: Obviously the x-label is incorrect here as the first bar should have the x-label 'G1', the second should have 'G2', etc, until we get to the last bar which is supposed to have 'G23'. If anyone knows how I can fix this, I would really, really appreciate it!