Issues with overlapping graphs in nested tiledlayouts
7 views (last 30 days)
Show older comments
Hello,
I'm trying to plot a series of humidograms by the airmass source region (aka cluster) and season the data was collected in. The for loop below is to help plot each season (if there is data from both seasons, as some clusters only appeared in one season) of the data per cluster, and so I made a nested tiledlayout, with the inner tiledlayout for the seasons and the outer tiledlayout for the clusters. I was going to work on resizing everything after figuring out this present issue, which is that everytime I run it, it plots each graph over top of another empty graph (as you can see in the photo below). The empty graph doesn't have any data in it and so I'm not exactly sure why it's doing this. And so, I'd like to see if someone sees anything that might be causing this issue or has any links to resources that could help me identify the issue.
Thank you

load('data table used in question.mat')
% should load any variables not explicitly set below
% Set individual variables
lbl_types = {'Only';'NH-3';'LH-2';'LH-3';'MH-2';'MH-3'}; % for color choice, ignore as I haven't added a legend yet
GFid = 4:12;
RHid = 13:21;
% Plot
figure("Position",[10 10 1000 500])
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
for i = 1:max(clsnum)
nexttile(t_lrg)
p_tbl_sum = mltm_dq_all{1,1}{i,1};
p_tbl_win = mltm_dq_all{2,1}{i,1};
if isempty(p_tbl_sum) % if only winter data
t = tiledlayout(t_lrg,1,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_win)
for k = 1:height(lbl_types)
if strcmp(p_tbl_win.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_win{j,GFid};
RHs = p_tbl_win{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_win(k,:))
hold on
else
continue
end
end
end
title([season{1,2},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
elseif isempty(p_tbl_win) % if only summer data
t = tiledlayout(t_lrg,1,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_sum)
for k = 1:height(lbl_types)
if strcmp(p_tbl_sum.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_sum{j,GFid};
RHs = p_tbl_sum{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_sum(k,:))
hold on
else
continue
end
end
end
title([season{1,1},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
else % if both seasons of data availible
t = tiledlayout(t_lrg,2,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_sum)
for k = 1:height(lbl_types)
if strcmp(p_tbl_sum.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_sum{j,GFid};
RHs = p_tbl_sum{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_sum(k,:))
hold on
else
continue
end
end
end
title([season{1,1},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
hold off
nexttile(t)
for j = 1:height(p_tbl_win)
for k = 1:height(lbl_types)
if strcmp(p_tbl_win.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_win{j,GFid};
RHs = p_tbl_win{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_win(k,:))
hold on
else
continue
end
end
end
title([season{1,2},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
end
end
t_lrg.Padding = "compact";
t_lrg.TileSpacing = 'compact';
title(t_lrg,'SKIO - 100 nm Particle Growth Factor Humidograms','FontWeight','bold');
3 Comments
dpb
on 10 Jul 2025
Edited: dpb
on 10 Jul 2025
In
if 0 % so can execute later code
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
for i = 1:max(clsnum)
nexttile(t_lrg)
p_tbl_sum = mltm_dq_all{1,1}{i,1};
p_tbl_win = mltm_dq_all{2,1}{i,1};
if isempty(p_tbl_sum) % if only winter data
t = tiledlayout(t_lrg,1,1); % inner layout
nexttile(t)
...
end
end
end
you create the outer tile and then a new tiledlayout object inside it...if there is only one, then the new one is the same size and overlays the t_lrg axes and so doesn't appear although it is behind the second just the same. If there are two, then they are smaller and so don't fully occlude the outer.
I am not quite sure the best way to produce the effect desired otomh, you might try simply setting 'Visible','off' for t_lrg; I'm not sure about t inheriting that and being invisible, too, or not. If so, then set the axes color to the background color to make it disappear.
I've not gotten terribly deep into just what one can do with tiledlayout whether it has a particular syntax for this or not; I'd study all the examples closely and see if there is anything that does something simliar to what you're wanting for ideas.
But, the above is where the outer axes is coming from; it's doing exacty what you told it to do... <lol>
It's easy enough to show what's happening...
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
nexttile(t_lrg) % make active
t = tiledlayout(t_lrg,1,1); % inner layout inside t_lrg
nexttile(t) % show it
figure
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
nexttile(t_lrg) % make active
t = tiledlayout(t_lrg,2,1); % inner layout inside t_lrg
nexttile(t) % show it
The above shows what was described above...let's spearmint about the visibility idea...
figure
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
h1=nexttile(t_lrg); % make active
t = tiledlayout(t_lrg,2,1); % inner layout inside t_lrg
nexttile(t) % show it
h1.Visible='off';
That does seem to fix the visibility issue; there's probably a better solution.
You still have an issue it appears of there being two axes even with the single inner axes, though. I didn't delve into that.
Accepted Answer
Matt J
on 10 Jul 2025
Remove the line
nexttile(t_lrg)
It creates an axes in the outer layout.
0 Comments
More Answers (1)
the cyclist
on 10 Jul 2025
Edited: the cyclist
on 10 Jul 2025
I think you don't want the very first nexttile call, just after
for i = 1:max(clsnum)
which creates the "underneath" axes, that are not used. Removing that line, and running your code here.
load('data table used in question.mat')
% should load any variables not explicitly set below
% Set individual variables
lbl_types = {'Only';'NH-3';'LH-2';'LH-3';'MH-2';'MH-3'}; % for color choice, ignore as I haven't added a legend yet
GFid = 4:12;
RHid = 13:21;
% Plot
figure("Position",[10 10 1000 500])
t_lrg = tiledlayout('flow','TileIndexing','rowmajor'); % outer layout
for i = 1:max(clsnum)
p_tbl_sum = mltm_dq_all{1,1}{i,1};
p_tbl_win = mltm_dq_all{2,1}{i,1};
if isempty(p_tbl_sum) % if only winter data
t = tiledlayout(t_lrg,1,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_win)
for k = 1:height(lbl_types)
if strcmp(p_tbl_win.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_win{j,GFid};
RHs = p_tbl_win{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_win(k,:))
hold on
else
continue
end
end
end
title([season{1,2},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
elseif isempty(p_tbl_win) % if only summer data
t = tiledlayout(t_lrg,1,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_sum)
for k = 1:height(lbl_types)
if strcmp(p_tbl_sum.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_sum{j,GFid};
RHs = p_tbl_sum{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_sum(k,:))
hold on
else
continue
end
end
end
title([season{1,1},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
else % if both seasons of data availible
t = tiledlayout(t_lrg,2,1); % inner layout
nexttile(t)
for j = 1:height(p_tbl_sum)
for k = 1:height(lbl_types)
if strcmp(p_tbl_sum.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_sum{j,GFid};
RHs = p_tbl_sum{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_sum(k,:))
hold on
else
continue
end
end
end
title([season{1,1},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
hold off
nexttile(t)
for j = 1:height(p_tbl_win)
for k = 1:height(lbl_types)
if strcmp(p_tbl_win.Distinction{j,:},lbl_types{k,:})
GFs = p_tbl_win{j,GFid};
RHs = p_tbl_win{j,RHid};
plot(RHs,GFs,'-diamond','Color',type_clr_win(k,:))
hold on
else
continue
end
end
end
title([season{1,2},' - ',clusnames{i,1}],'FontSize',9);
ylabel('GF','FontSize',8); xlabel('Relative Humidity (%)','FontSize',8);
ylim([0.98 1.7]);
xlim([48 92]);
t.Layout.Tile = i;
t.Layout.TileSpan = [1,1];
t.TileSpacing = 'tight';
t.Padding = "compact";
hold off
end
end
t_lrg.Padding = "compact";
t_lrg.TileSpacing = 'compact';
title(t_lrg,'SKIO - 100 nm Particle Growth Factor Humidograms','FontWeight','bold');
0 Comments
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!