Add X Labels to Bar Graph
Show older comments
Hi, I need help getting the X Axis labels to be complete.. I'd like to label every bar and have the years at a 45 degree angle. Code below.... thanks!

ax.XTickMode = 'manual';
ax.XTick = 1:24; %24 years of data, so I want 24 labels!
%ax.XTick = [0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15]; %tried making the bins tiny didn't help
ax.XTickLabels = {'2000','2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023'};
ax.XTickLabelRotation = 45;
w1 = 1; %this is how i figured out to get both data sets plotted on the same bar graph
bar(years,more,w1,'FaceColor',[0.4784 0.4627 0.4627])
w2 = 1;
hold on
bar(years,less,w2,'FaceColor',[0.8000 0.8000 0.8000])
hold off
grid on
ylabel('August Precipitation (in)')
legend({'Higher than Average','Lower than Average'},'Location','northeast')
Accepted Answer
More Answers (0)
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!