How to prevent legend from overlapping with x-axis

10 ビュー (過去 30 日間)
Hasan Isomitdinov
Hasan Isomitdinov 2022 年 12 月 21 日
コメント済み: Voss 2022 年 12 月 22 日
Hi,
I am trying to plot a tiledlayout but my legend keeps going over the x axis of my last few graphs. How do I tell Matlab to position the legend below all charts? Thank you.
I will attach the plot and the code I am running below.
figure(1)
t = tiledlayout(5,5,'TileSpacing','Compact','Padding','Compact');
for i=1:23
nexttile
area(dates,[vdemg_out(:,i,1),vdemr_out(:,i,1),vdemi_out(:,i,1)],'FaceColor','flat')
a11 = sprintf('%s',country{i});
title(a11);
xtickangle(45)
ylim([0 1]);
xlim([1980 max(dates)]);
ax = gca;
set(ax, 'XTick', 1980:10:2015,'TickDir','out')
grid on
end
lgn = legend({'Global','Regional','Country-specific'},'Location','bestoutside');
set(lgn,'Position',[2.52 0.0 5 0.4]*0.1,'NumColumns',3);
  1 件のコメント
millercommamatt
millercommamatt 2022 年 12 月 21 日
Does lgd.Layout.Tile = 'east'; help?

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

採用された回答

Voss
Voss 2022 年 12 月 22 日
% making up some data:
dates = [1980 2000 2020];
vdemg_out = rand(3,23);
vdemr_out = rand(3,23);
vdemi_out = rand(3,23);
country = num2cell('A':'W');
figure(1)
t = tiledlayout(5,5,'TileSpacing','Compact','Padding','Compact');
for i=1:23
nexttile
area(dates,[vdemg_out(:,i,1),vdemr_out(:,i,1),vdemi_out(:,i,1)],'FaceColor','flat')
a11 = sprintf('%s',country{i});
title(a11);
xtickangle(45)
ylim([0 1]);
xlim([1980 max(dates)]);
ax = gca;
set(ax, 'XTick', 1980:10:2015,'TickDir','out')
grid on
end
lgn = legend({'Global','Regional','Country-specific'},'NumColumns',3);
lgn.Layout.Tile = 'south';
  2 件のコメント
Hasan Isomitdinov
Hasan Isomitdinov 2022 年 12 月 22 日
Thank you very much!
Voss
Voss 2022 年 12 月 22 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by