Help using tiledlayout and nexttile functions

Hello.
I will really be appreciated if someone could help me with the follow inquiry:
I am trying to plot several subplots using tiledlayout and nexttile functions, however I am not getting the final plot as I would like (i.e., 8-by-2 tiled chart layout).
Any help is more than welcome.
Regards.
clear;
data = readmatrix('Data2');
T = data(:,1);
T = seconds(data(:,1));
T.Format = 'hh:mm';
T3 = data(:,3);
T4 = data(:,4);
T5 = data(:,5);
T6 = data(:,6);
T7 = data(:,7);
T8 = data(:,8);
T9 = data(:,9);
T10 = data(:,10);
T11 = data(:,11);
T12 = data(:,12);
T13 = data(:,13);
T14 = data(:,14);
T15 = data(:,15);
T16 = data(:,16);
tiledlayout(8,2);
nexttile
%figure; % Place "figure" in this section allow to plot this data in a separate window.
plot (T,T3,'x');
title 'Emitted Signal from NAA Station';
ylabel ('Phase');
xlabel ('Samples');
nexttile
%figure;
plot (T,T4,'x');
title 'Emitted Signal from NAA Station';
ylabel ('Apmlitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T5,'x');
title 'Emitted Signal from NLK Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T6,'x');
title 'Emitted Signal from NLK Station';
ylabel ('Amplitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T7,'x');
title 'Emitted Signal from NDK Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T8,'x');
title 'Emitted Signal from NDK Station';
ylabel ('Amplitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T9,'x');
title 'Emitted Signal from NWC Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T10,'x');
title 'Emitted Signal from NWC Station';
ylabel ('Amplitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T11,'x');
title 'Emitted Signal from NPM Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T12,'x');
title 'Emitted Signal from NPM Station';
ylabel ('Amplitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T13,'x');
title 'Emitted Signal from NPM II Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T14,'x');
title 'Emitted Signal from NPM II Station';
ylabel ('Amplitude');
xlabel ('Samples');
% figure;
nexttile
plot (T,T15,'x');
title 'Emitted Signal from NAU Station';
ylabel ('Phase');
xlabel ('Samples');
% figure;
nexttile
plot (T,T16,'x');
title 'Emitted Signal from NAu Station';
ylabel ('Amplitude');
xlabel ('Samples');
Regards.

 採用された回答

the cyclist
the cyclist 2023 年 7 月 8 日

0 投票

It's unclear to me what you are expecting to get, but this code works exactly as I would expect.
You have defined an 8x2 grid of plots, but you have only actually called nexttile/plot 14 times. Therefore, you fill in the first 14 subplot slots (in the default order, which is row-major). The last 2 slots are empty.

4 件のコメント

Angel Lozada
Angel Lozada 2023 年 7 月 9 日
Dear the cyclist
Thanks for your reply.
I called nexttile/plot 14 times because I am plotting 14 different data. I am sure there is a short way to do it, but the current one is how I figured out to do it.
I am looking to get an image like the attached one named VLF_220919_E (just for referece).
In the attached file named mat2, it is possible to see what I looking to get and what I got it.
Regards.
the cyclist
the cyclist 2023 年 7 月 9 日
There are many differences between the expected and actual. Here are some I notice:
  • Expected has 12 subplots instead of 14
  • Expected does not have x- or y-axis labels
  • Expected does not have x-axis tick labels (the numbers)
  • Actual has larger, bold titles for each subplot
  • In your code, you made an 8x2 grid of subplots, which leaves 2 empty spaces. You could have used 7x2.
  • The data between the two plots seems different. It seems that higher data density in actual plot makes it less readable?
  • Expected has grid lines
The overall effect of many of these differences is to make the subplots more "crowded", which I assume is what you don't like. But we don't know which of these elements are important to keep for you use case.
Angel Lozada
Angel Lozada 2023 年 7 月 9 日
Dear the cyclist.
Thanks for your support, I really appreciated all your suggestions.
The attached figure that show the "expected" plots, is just for reference; is the same kind of data but not the same data.
What I would like is the box size for each subplot could be looks like the "expected" one.
Is there a way to enlarge the high of each box size?
Regards
clear;
data = readmatrix('Data2');
n=200;
T = data(:,1);
% T = seconds(data(:,1));
%T.Format = 'hh:mm';
T3 = data(:,3);
m3 = movmean (T3,n);
T4 = data(:,4);
m4 = movmean (T4,n);
T5 = data(:,5);
m5 = movmean (T5,n);
T6 = data(:,6);
m6 = movmean (T6,n);
T7 = data(:,7);
m7 = movmean (T7,n);
T8 = data(:,8);
m8 = movmean (T8,n);
T9 = data(:,9);
m9 = movmean (T9,n);
T10 = data(:,10);
m10 = movmean (T10,n);
T11 = data(:,11);
m11 = movmean (T11,n);
T12 = data(:,12);
m12 = movmean (T12,n);
T13 = data(:,13);
m13 = movmean (T13,n);
T14 = data(:,14);
m14 = movmean (T14,n);
T15 = data(:,15);
m15 = movmean (T15,n);
T16 = data(:,16);
m16 = movmean (T16,n);
tiledlayout(7,2);
nexttile
plot (T,m3,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title ('\fontsize{6}Emitted Signal from NAA Station');
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m4,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NAA Station';
% ylabel ('Apmlitude');
% xlabel ('Samples');
nexttile
plot (T,m5,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NLK Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m6,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NLK Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
nexttile
plot (T,m7,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NDK Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m8,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NDK Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
nexttile
plot (T,m9,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NWC Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m10,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NWC Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
nexttile
plot (T,m11,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NPM Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m12,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NPM Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
nexttile
plot (T,m13,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NPM II Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m14,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NPM II Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
nexttile
plot (T,m15,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NAU Station';
% ylabel ('Phase');
% xlabel ('Samples');
nexttile
plot (T,m16,'-');
set(gca,'YTick',[]);
set(gca,'XTick',[]);
title '\fontsize{6}Emitted Signal from NAu Station';
% ylabel ('Amplitude');
% xlabel ('Samples');
the cyclist
the cyclist 2023 年 7 月 10 日
編集済み: the cyclist 2023 年 7 月 19 日
It will help to use compact tile spacing and padding. Call tiledlayout with a handle:
t = tiledlayout(7,2);
and then run
t.TileSpacing = 'compact';
t.Padding = 'compact';
This will reduce the white space. Other than that, I'm not sure there is much more you can do to make the subplots larger.

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

その他の回答 (0 件)

製品

リリース

R2022a

質問済み:

2023 年 7 月 8 日

編集済み:

2023 年 7 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by