Align xticklabels along horizontal line

16 ビュー (過去 30 日間)
Petr Michalek
Petr Michalek 2023 年 10 月 23 日
回答済み: Walter Roberson 2023 年 10 月 23 日
Hello,
I have this bar chart, and I need that the xticklabels (the days) have to be aligned along horizontal line. I need, that the days start at the same horizontal line. The days are defined as categorical values:
Xday1=categorical({'Jan.3','Jan.4','Jan.12','Jan.13','Feb.23','Feb.24','Mar.1','Mar.2','Apr.6', ...
'Jun.12','Jun.16','Jul.12','Jul.13','Oct.5','Oct.27','Oct.28','Oct.29','Nov.19','Nov.20'});
Xday1=reordercats(Xday1,{'Jan.3','Jan.4','Jan.12','Jan.13','Feb.23','Feb.24','Mar.1','Mar.2','Apr.6', ...
'Jun.12','Jun.16','Jul.12','Jul.13','Oct.5','Oct.27','Oct.28','Oct.29','Nov.19','Nov.20'});
Also, I need to double or triple the bar width, but when I set the bar widths to 2, the bars start ovelapping.
Any help would be appreciated.
Petr
  4 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 10 月 23 日
What are the variables used in the call to bar()? Provide the values for them as well.
Also, why are you dynamically naming variables?
Petr Michalek
Petr Michalek 2023 年 10 月 23 日
I am sorry, but you are asking for something completely different than I was asking. If you want to recreate my chart (sort of), just give to the variables some random numbers. I wanted to know how to align the Xtick Labels.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 10 月 23 日
In theory...
labels = {'123', '1234', '12345678'};
ax = gca;
bar(ax, [3 5 7])
xticks(ax, 1:3)
xlim(ax, [0 4])
xticklabels(ax, labels)
xtickangle(ax, 90)
drawnow(); %needed or TickLabelChild will be empty
ax.XAxis.TickLabelChild.HorizontalAlignment = 'right'; %left center right
ax.XAxis.TickLabelChild.VerticalAlignment = 'bottom'; %top middle bottom
You can see in practice it does not work

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by