How do I add a month as the xlabel on a grouped bar graph?
4 views (last 30 days)
Show older comments
I need to have a month on the base of each group of values and a legend for what each bar is for.
My code with simplified vectors is as follows: figure x = categorical({'March' 'April'}); y = [2 4 6; 3 4 5]; b = bar(x,y); title('Breakdown of the average pump power consumption') ylabel('Average Power (kW)') xlabel('Month') labels = {'Overall','Fey Pivot','Pods'}; legend(labels,'Location','southoutside','Orientation','horizontal')
0 Comments
Answers (1)
dpb
on 26 May 2017
You can try it, but I doubt the ticklabel property has been updated to accept categorical variables--
set(gca,'xticklabel',x)
What I know will work will be to cast to char
set(gca,'xticklabel',char(x))
Don't have HG2 here, so can't test the former; bar isn't categorical-aware...
0 Comments
See Also
Categories
Find more on Labels and Annotations 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!