MATLAB Answers

bar plot

11 views (last 30 days)
Hassan
Hassan on 30 Jun 2011
I am making a bar plot. I want to put text labels for each x value. the text lables, however, are located at the end of each bar on X axis. I wonder how I can put them in the center of bars. I apperciate your help.
  2 Comments
Hassan
Hassan on 30 Jun 2011
Hi Rick,
n=[3237 8359 1381 9172 3737 3548 7582]
l={'oilseed rape','wheat','bare soil','grassland','built-up','field beans','barley'};
bar(n)
set(gca,'xticklabel',l.')

Sign in to comment.

Accepted Answer

Paulo Silva
Paulo Silva on 30 Jun 2011
Using my magic ball I will try to answer the question with one example made by me and based on the reference at the bottom
fruit = [2 5 6 7]
h=bar(fruit)
l={'apples', 'oranges', 'strawberries', 'pears'}
y=get(h,'Ydata');
x=get(h,'Xdata');
text(x-x(1)/3,y/2,l,'FontSize',18)
  3 Comments
Hassan
Hassan on 30 Jun 2011
Sorry Paulo for misspelling your name. Thanks a lot for the help.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!