labels not showing for subplots - using xTicks xTickLabels

I need to specify where does a new hour start while plotting HRV data. As this happens at specific locations along my vector, while not having the same amount of samples in each hour, I use Xticks and XTickLabels. Please see my code below. My problem is that, the labels are shown only for my first subplot. Tried moving the set function before-after plot, it didn't help. I guess it is something with how Matlab handles axis or something, but I couldn't figure it out. Could anyone help with this matter?
%% data generation
X = rand([106378,1]);
one_plot = 20000;
hour_sub1 = [6066;11769;17113];
tick_label_1 = 1:size(hour_sub1);
hour_sub2 = [22485;27750;33093;38320];
tick_label_2 = tick_label_1(end)+1 : tick_label_1(end)+1 + size(hour_sub2)-1;
hour_sub3 = [44098; 49094; 54066; 58149];
tick_label_3 = tick_label_2(end)+1 : tick_label_2(end)+1 + size(hour_sub3)-1;
hour_sub4 = [62221; 66445; 70065;73916;77564];
tick_label_4 = tick_label_3(end)+1 : tick_label_3(end)+1 + size(hour_sub4)-1;
hour_sub5 = [81399; 84976; 88595; 92340; 97793];
tick_label_5 = tick_label_4(end)+1 : tick_label_4(end)+1 + size(hour_sub5)-1;
hour_sub6 = 103341
tick_label_6 = tick_label_5(end)+1 : tick_label_5(end)+1 + size(hour_sub6)-1;
%% Plotting problem
figure
subplot(6,1,1)
%figure
plot(X(1:one_plot))
set(gca, 'XTick', hour_sub1, 'XTickLabel', tick_label_1);
ylim([0.0, 3])
subplot(6,1,2)
%figure
plot(X(one_plot+1:2*one_plot))
set(gca, 'XTick', hour_sub2, 'XTickLabel', tick_label_2)
ylim([0.0, 3])
subplot(6,1,3)
%figure
plot(X(2*one_plot+1:3*one_plot))
set(gca, 'XTick', hour_sub3, 'XTickLabel', tick_label_3)
ylim([0.0, 3])
subplot(6,1,4)
%figure
plot(X(3*one_plot+1:4*one_plot))
set(gca, 'XTick', hour_sub4, 'XTickLabel', tick_label_4)
ylim([0.0, 3])
subplot(6,1,5)
%figure
plot(X(4*one_plot+1:5*one_plot))
set(gca, 'XTick', hour_sub5, 'XTickLabel', tick_label_5)
ylim([0.0, 3])
subplot(6,1,6)
%figure
plot(X(5*one_plot+1:size(X)))
set(gca, 'XTick', hour_sub6, 'XTickLabel', tick_label_6)
ylim([0.0, 3])

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 26 日

0 投票

You forgot to specify the x-coordinates in plot(). Try this
%% Plotting problem
figure
subplot(6,1,1)
%figure
plot(1:one_plot, X(1:one_plot))
set(gca, 'XTick', hour_sub1, 'XTickLabel', tick_label_1);
ylim([0.0, 3])
subplot(6,1,2)
%figure
plot(one_plot+1:2*one_plot, X(one_plot+1:2*one_plot))
set(gca, 'XTick', hour_sub2, 'XTickLabel', tick_label_2)
ylim([0.0, 3])
subplot(6,1,3)
%figure
plot(2*one_plot+1:3*one_plot, X(2*one_plot+1:3*one_plot))
set(gca, 'XTick', hour_sub3, 'XTickLabel', tick_label_3)
ylim([0.0, 3])
subplot(6,1,4)
%figure
plot(3*one_plot+1:4*one_plot, X(3*one_plot+1:4*one_plot))
set(gca, 'XTick', hour_sub4, 'XTickLabel', tick_label_4)
ylim([0.0, 3])
subplot(6,1,5)
%figure
plot(4*one_plot+1:5*one_plot, X(4*one_plot+1:5*one_plot))
set(gca, 'XTick', hour_sub5, 'XTickLabel', tick_label_5)
ylim([0.0, 3])
subplot(6,1,6)
%figure
plot(5*one_plot+1:size(X), X(5*one_plot+1:size(X)))
set(gca, 'XTick', hour_sub6, 'XTickLabel', tick_label_6)
ylim([0.0, 3])

2 件のコメント

Tamás Böndi
Tamás Böndi 2020 年 4 月 26 日
awesome, thanks!
Ameer Hamza
Ameer Hamza 2020 年 4 月 26 日
I am glad to be of help.

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by