How to unfade legend placed on an empty (invisible) plot?
Show older comments
I am trying to make a figure with three plots, and use the fourth one to place the legend. I set that last plot as invisible but then the legend is also faded. How can I fix that?
Here is the relevant code:
fig = figure();
subplot(1,4,1)
plot(x1(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X1');
subplot(1,4,2)
plot(x2(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X2');
subplot(1,4,3)
plot(x3(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X3');
subplot(1,4,4)
plot(x3(:,[1:15]),'Visible','off');
legend(labels,'FontSize',12,'Location','best');
axis off;
sgtitle('Lines');
set(fig,'Units','normalized','Position',[0 0 3 1.5]);
Accepted Answer
More Answers (1)
Adam Danz
on 29 Mar 2024
With tiledlayout, the placement of the legend and the global title can be part of the layout.
fig = figure();
tcl = tiledlayout(1,4); % <----- used tiledlayout
nexttile() % <----- call nexttile instead of subplot
plot(x1(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X1');
nexttile() % <----- call nexttile instead of subplot
plot(x2(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X2');
nexttile() % <----- call nexttile instead of subplot
plot(x3(:,[1:15]),'LineWidth',3);
ylim([-0.3 1.2]);
title('X3');
leg = legend(labels,'FontSize',12,'Location','best');
leg.Layout.Tile = 4 % <----- assign legend to 4th tile location
title(tcl,'Lines'); % <----- Set the title of the entire layout instead of sgtitle
set(fig,'Units','normalized','Position',[0 0 3 1.5]);
Categories
Find more on 2-D and 3-D Plots 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!
