Add individual legends to plots in a tiledlayout
Hi,
I would like to create a tiled layout with both a tile-specific and a common legend.
The tile-specific legend should contain a reference to the data contained only on the tile, whereas the common legend should refer to data across all tiles.
Here is a simple code to illustrate what I’m trying to do. The tile legends should refer to the yline and the common legend at the bottom should refer to data in all plots. Hopefully this makes sense.
Can anybody help?
Thank you
x = linspace(0,30);
y1 = sin(x);
y2 = sin(x);
figure
tiledlayout(1,2)
ax1 = nexttile(1);
plot(x,y1)
yline(0,’–‘)
legend(ax1, ”, ‘y=0’)
ax2 = nexttile(2);
plot(x,y2)
yline(0.5,’–‘)
legend(ax2, ”, ‘y=0.5’)
leg = legend(‘sin(x)’);
leg.Layout.Tile = ‘south’;Hi,
I would like to create a tiled layout with both a tile-specific and a common legend.
The tile-specific legend should contain a reference to the data contained only on the tile, whereas the common legend should refer to data across all tiles.
Here is a simple code to illustrate what I’m trying to do. The tile legends should refer to the yline and the common legend at the bottom should refer to data in all plots. Hopefully this makes sense.
Can anybody help?
Thank you
x = linspace(0,30);
y1 = sin(x);
y2 = sin(x);
figure
tiledlayout(1,2)
ax1 = nexttile(1);
plot(x,y1)
yline(0,’–‘)
legend(ax1, ”, ‘y=0’)
ax2 = nexttile(2);
plot(x,y2)
yline(0.5,’–‘)
legend(ax2, ”, ‘y=0.5’)
leg = legend(‘sin(x)’);
leg.Layout.Tile = ‘south’; Hi,
I would like to create a tiled layout with both a tile-specific and a common legend.
The tile-specific legend should contain a reference to the data contained only on the tile, whereas the common legend should refer to data across all tiles.
Here is a simple code to illustrate what I’m trying to do. The tile legends should refer to the yline and the common legend at the bottom should refer to data in all plots. Hopefully this makes sense.
Can anybody help?
Thank you
x = linspace(0,30);
y1 = sin(x);
y2 = sin(x);
figure
tiledlayout(1,2)
ax1 = nexttile(1);
plot(x,y1)
yline(0,’–‘)
legend(ax1, ”, ‘y=0’)
ax2 = nexttile(2);
plot(x,y2)
yline(0.5,’–‘)
legend(ax2, ”, ‘y=0.5’)
leg = legend(‘sin(x)’);
leg.Layout.Tile = ‘south’; tiled layout MATLAB Answers — New Questions