How to specify your own (not numerical) categories on the x-axis of a box plot?
85 views (last 30 days)
Show older comments
I want to create a box plot where on the x-axis I have not numbers but categories, e.g. countries (France, Belgium, Netherlands etc). The y-axis just numerical, e.g., the box height represents GDP per person in a particular country. How do I specify the x-axis?
0 Comments
Accepted Answer
the cyclist
on 11 Sep 2013
Here is one way
countries = {'Botswana','Lesotho','Iceland'};
x1 = randn(1000,3);
x2 = rand(1,3);
figure
boxplot(x1)
set(gca,'XTick',1:3,'XTickLabel',countries)
figure
bar(x2)
set(gca,'XTick',1:3,'XTickLabel',countries)
You said "box plot", but what you described sounds more like a "bar chart", so I gave you a simple example of each.
3 Comments
the cyclist
on 11 Sep 2013
It's not super-easy. See this page for some suggestions on that:
Personally, I like the xticklabel_rotate function that is mentioned about halfway down that page.
More Answers (1)
Sabiha Mahzabeen
on 29 Nov 2018
How can i get histogram where y-axis with percentages and x-axis with categorical variables?
Airline={'Air Canada', 'Delta Airline','American Airline'};
y lebel=[.20 .35 .25 ];
0 Comments
See Also
Categories
Find more on Axes Appearance 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!