How can I title my bar graph in x-axis?

334 ビュー (過去 30 日間)
M G
M G 2011 年 9 月 30 日
コメント済み: Philippe Corner 2018 年 1 月 26 日
Hey,
As you know the default for x-axis in the Bar graph is just numbers. Could you please give me a hint how I can replace them by names? e.g. I would like to have a bar graph with the names of months (Jan, Feb, Mar, ...)in the x-axis.
Thank you,
Mehdi

採用された回答

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 30 日
I have no idea why. This code should work:
figure
name = {'m1';'m2';'m3';'m4';'m5'};
x = [1:5]; y = [19,24,42,12,14];
bar(x,y)
set(gca,'xticklabel',name)
  2 件のコメント
Joelmir
Joelmir 2017 年 5 月 25 日
Very good!! thanks
Philippe Corner
Philippe Corner 2018 年 1 月 26 日
Hi Grzegorz Knor, how could i name the xbars in a sequence.. for example to have numbers from 1:1:10.

サインインしてコメントする。

その他の回答 (2 件)

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 30 日
bar(1:12)
set(gca,'xticklabel',{'a','b','c','d','e','f','g','h','i','j','k','l'})

M G
M G 2011 年 9 月 30 日
Thank you Grzegorz, At the moment I have a cell array containing names:
fname = {'m1','m2','m3','m4','m5'};
and when I name them in the x-axis as you mentioned:
x = [1:5]; y = [19,24,42,12,14]; name = [fanme];
bar(x,y)
set(gca,'xticktlabel',name)
each of columns are named as m1m2m3m4m5
How can I have m1 for column1, m2 for column2 and so on?
  1 件のコメント
Mara
Mara 2017 年 2 月 16 日
Your problem can be solved like this:
fname = {'m1','m2','m3','m4','m5'};
x = [1:5]; y = [19,24,42,12,14];
bar(x,y)
set(gca, 'XTick', 1:length(fname),'XTickLabel',fname);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Data Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by