How do I make bar graph spacing equal?

Y = [2021 2021 2021 2021 2021] ;
M = [02 02 02 02 03] ;
D = [09 17 22 24 02];
x = datetime(Y,M,D) ;
y = [2.1 9 9.9 12.4 5] ;
figure
bar(x,y)
set(gca,'FontSize',8.5)
ylabel('Temperature (degrees Celsius)')
xlabel('Date')
axis tight
I have temperature on the y axis and dates on the x axis but the spacing is uneven. How do I make the spacing equal?
Thanks :)

 採用された回答

Star Strider
Star Strider 2021 年 5 月 29 日

2 投票

One approach —
Y = [2021 2021 2021 2021 2021] ;
M = [02 02 02 02 03] ;
D = [09 17 22 24 02];
x = datetime(Y,M,D);
y = [2.1 9 9.9 12.4 5] ;
figure
bar(y)
set(gca,'FontSize',8.5)
ylabel('Temperature (degrees Celsius)')
xlabel('Date')
set(gca, 'XTick',1:numel(x), 'XTickLabel',string(x))
axis tight
.

2 件のコメント

AAK
AAK 2021 年 5 月 29 日
Thanks so much! :)
Star Strider
Star Strider 2021 年 5 月 29 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

AAK
2021 年 5 月 29 日

コメント済み:

2021 年 5 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by