# Legends size using "Show" function

I have two graphs:

Plot[{x, x^2, x^3}, {x, 0, 3}, PlotRange -> {0, 27},
AxesOrigin -> {0, 0}, AspectRatio -> 0.75,
PlotStyle -> {{Black}, {Black, Dotted}, Black},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends -> {"func. 1", "func. 2", "func. 3"}]


Show[
Plot[x, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends -> {"func. 1"}],
Plot[x^2, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black, Dotted},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends -> {"func. 2"}],
Plot[x^3, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends -> {"func. 3"}]]


I would like to do the legends on the second graphs the same as on the first one. It's clear that they have different vertical shift and the line length. So, I would like to do the second legends identical to the first one if possible, of course :)

Use LegendMarkerSize in conjunction with a LineLegend.

Show[
Plot[x^3, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black, Dashed},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends ->
Placed[LineLegend[{Directive[Black, Thin, Dashed]}, {"func. 1"},
LegendMarkerSize -> 20], After]]
, Plot[x^2, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black, Dotted},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends ->
Placed[LineLegend[{Directive[Black, Dotted]}, {"func. 2"},
LegendMarkerSize -> 20], After]]
, Plot[x, {x, 0, 3}, PlotRange -> {0, 27}, AxesOrigin -> {0, 0},
AspectRatio -> 0.75, PlotStyle -> {Black, Thin},
AxesLabel -> {Style["x", 18], Style["y", 18]}, LabelStyle -> {13},
PlotLegends ->
Placed[LineLegend[{Directive[Black, Thin]}, {"func. 3"},
LegendMarkerSize -> 20], After]]
]


I have renamed functions to ensure that the legend corresponds to the order in which the curves appear. However, a better way would be to combine plots and legends inside a Plot command and then to use the LegendLayout function as shown in 256344.

EDIT

To control the spacing: use {1, 0.7}, {1, 0.65}, {1, 0.6} as an example instead of the After in the plots, respectively.

• Thanks so much. Your example with LegendMarkerSize and LineLegend is exactly what I need. I will use it in both cases. Jun 2, 2022 at 12:42