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일
It would be better if you can attach all the relevant code used to produce the bar chart and things related to it.
Okay, here is the code for the figure:
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'});
figure (1)
b1=bar(Xday1,[itcs20usek1(1) itcs40usek1(1) itcs60usek1(1) itcs80usek1(1); itcs20usek2(1) itcs40usek2(1) itcs60usek2(1) itcs80usek2(1); ... 1, 2
itcs20usek14(1) itcs40usek14(1) itcs60usek14(1) itcs80usek14(1); itcs20usek15(1) itcs40usek15(1) itcs60usek15(1) itcs80usek15(1); ... 14, 15
itcs20usek3(1) itcs40usek3(1) itcs60usek3(1) itcs80usek3(1); itcs20usek4(1) itcs40usek4(1) itcs60usek4(1) itcs80usek4(1); ... 3, 4
itcs20usek16(1) itcs40usek16(1) itcs60usek16(1) itcs80usek16(1); itcs20usek5(1) itcs40usek5(1) itcs60usek5(1) itcs80usek5(1); ... 16, 5
itcs20usek6(1) itcs40usek6(1) itcs60usek6(1) itcs80usek6(1); itcs20usek7(1) itcs40usek7(1) itcs60usek7(1) itcs80usek7(1); ... 6, 7
itcs20usek8(1) itcs40usek8(1) itcs60usek8(1) itcs80usek8(1); itcs20usek9(1) itcs40usek9(1) itcs60usek9(1) itcs80usek9(1); ... 8, 9
itcs20usek10(1) itcs40usek10(1) itcs60usek10(1) itcs80usek10(1); itcs20usek11(1) itcs40usek11(1) itcs60usek11(1) itcs80usek11(1); ... 10, 11
itcs20usek21(1) itcs40usek21(1) itcs60usek21(1) itcs80usek21(1); itcs20usek22(1) itcs40usek22(1) itcs60usek22(1) itcs80usek22(1); ... 21, 22
itcs20usek23(1) itcs40usek23(1) itcs60usek23(1) itcs80usek23(1); ... 23
itcs20usek12(1) itcs40usek12(1) itcs60usek12(1) itcs80usek12(1); itcs20usek13(1) itcs40usek13(1) itcs60usek13(1) itcs80usek13(1)]); % 12, 13
Unrecognized function or variable 'Xday1'.
b1(1).FaceColor = [0 0 0]; b1(2).FaceColor = [1 1 1];
b1(3).FaceColor = [.5 .5 .5]; b1(4).FaceColor = [.25 .25 .25];
ylabel('$\sigma_u/u*$','Interpreter','latex'); % xlabel('day');
leg=legend('H=20m','H=40m','H=60m','H=80m');
set(leg,'interpreter','latex'); legend('boxoff');
ylim([0 4]); ax=gca; ax.FontSize=14;
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

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 10월 23일

답변:

2023년 10월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by