Force x axis to start at origin

Hi,
I want to make a bar chart in MATLAB R2016b. For some reason the x-axis does not start in the origin of the x- and y-axis. Does anyone know how you can force it to start there? Now it starts a couple of centimeters to the right which results in the values on the x-axis to be placed very close to each other (see figure).
This is the code I use:
b= bar(timespan,combi,'FaceColor',orange);
b(2).FaceColor= cyaan;
xlabel('Local Time [hrs]')
ylabel('# flights')
xticks(timespan)
With timespan being a matrix defining the hours of the day 0:23. And combi being a 24x2 matrix defining 2 columns of operation data.
Thanks in advance.

 採用された回答

KSSV
KSSV 2016 年 11 月 30 日
編集済み: KSSV 2016 年 11 月 30 日

2 投票

Use xlim. Doc xlim.
xlim([0. 24])

6 件のコメント

Bas
Bas 2016 年 11 月 30 日
I tried that one, but that gives only x-axis values in time steps of 5 (0 5 10 15 20). I would like to see all integers between 0 and 24..
KSSV
KSSV 2016 年 11 月 30 日
Try axis tight.
If not use xlim and you have to play around with xticks
Bas
Bas 2016 年 11 月 30 日
Thanks that works
Manjula
Manjula 2017 年 12 月 15 日
Thank you, you saved my time.
Niki Drossinos
Niki Drossinos 2023 年 11 月 1 日
Thank you so much, this was really helpful!
Steven Lord
Steven Lord 2023 年 11 月 1 日
FYI, in the years since this question was asked we've introduced a number of functions and functionality for customizing the appearance of the axes. Take a look at the functions listed on this page for more information.

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

その他の回答 (0 件)

カテゴリ

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

タグ

質問済み:

Bas
2016 年 11 月 30 日

コメント済み:

2023 年 11 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by