How to prevent legend from overlapping with x-axis

11 visualizaciones (últimos 30 días)
Hasan Isomitdinov
Hasan Isomitdinov el 21 de Dic. de 2022
Comentada: Voss el 22 de Dic. de 2022
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);

Respuesta aceptada

Voss
Voss el 22 de Dic. de 2022
% 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';

Más respuestas (0)

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by