Skip to content

Instantly share code, notes, and snippets.

@hongyangqin
Created January 5, 2018 14:30
Show Gist options
  • Save hongyangqin/55b4d3ba93e454b053de72df420b9190 to your computer and use it in GitHub Desktop.
Save hongyangqin/55b4d3ba93e454b053de72df420b9190 to your computer and use it in GitHub Desktop.
Matlab How to create bar graph with categorical data

How to create bar graph with categorical data

from : https://cn.mathworks.com/matlabcentral/answers/329953-how-to-create-bar-graph-with-categorical-data

I would like to plot a bar graph separated in categories. I tried out the example code here from Matlab Documentation:

c = categorical({'apples','oranges','pears'});
prices = [1.23 0.99 2.3];
bar(c,prices);

But I don't get the categories displayed on the "x-Axis" of the graph, instead just int's 1-3.

Answer by Gautam Ilango on 18 Mar 2017

 Accepted Answer

Meanwhile I have found this workaround:

prices = [1.23 0.99 2.3];
bar(prices);
set(gca,'xticklabel',{'apples','oranges','pears'});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment