Labeling bar charts with over 15 categories
4 views (last 30 days)
Show older comments
I'm generating a simple bar-chart with category names on the x-axis. All seems to work fine when the number of categories is 15 or less. For 16 (or more) categories, the chart plots OK but the x-axis labels are not right. I'm using MatLab 2015b.
% Set number of categories.
num_categories = 16;
% Create data.
values = rand(1,num_categories);
% Create category names.
symbols = ['a':'z'];
string_length = 5;
for i = 1:num_categories
nums = randi(numel(symbols),[1 string_length]);
category_name(i) = cellstr(symbols(nums));
end
% Plot bar-chart.
bar(values)
set(gca,'XTickLabel',category_name)
set(gca,'XTickLabelRotation',90)
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Labels and Annotations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!