# How do I put the PlotLabel inside the graph?

I have this code:

basep = Plot[{p[x, y, t, baseta, f, basefa, baseul]*150}, {x, 0, basexhat}, PlotLabel -> "Rental price per m^2", PlotStyle -> {Opacity[0.5]}]
baseq = Plot[{q[x, y, t, baseta, f, basefa, baseul]}, {x, 0, basexhat}, PlotLabel -> "Dwelling size", PlotStyle -> {Opacity[0.5]}]
baser = Plot[{r[x, y, t, baseta, f, basefa, baseul]*150}, {x, 0, basexhat}, PlotLabel -> "Land rental price per m^2", PlotStyle -> {Opacity[0.5]}]
baseh = Plot[{h[x, y, t, baseta, f, basefa, baseul]}, {x, 0, basexhat}, PlotLabel -> "Floor to area ratio", PlotStyle -> {Opacity[0.5]}]
baseDen = Plot[{Den[x, y, t, baseta, f, basefa, baseul]*10}, {x, 0, basexhat}, PlotLabel -> "Population density", PlotStyle -> {Opacity[0.5]}]
baseL = Plot[{L[x, y, t, baseta, f, basefa, baseul]/1000}, {x, 0, basexhat}, PlotLabel -> "Population (1000s)", PlotStyle -> {Opacity[0.5]}, Epilog -> {Dashed, LightBlue,
Line[{{basexhat, 0}, {basexhat, 600}}], Dashed, LightBlue,
Line[{{lastxhat, 0}, {lastxhat, 600}}]}]
lastp = Plot[{p[x, y, t, lastta, f, lastfa, lastul]*150}, {x, 0, lastxhat}, PlotLabel -> "Rental price per m^2"]
lastq = Plot[{q[x, y, t, lastta, f, lastfa, lastul]}, {x, 0, lastxhat}, PlotLabel -> "Dwelling size"]
lastr = Plot[{r[x, y, t, lastta, f, lastfa, lastul]*150}, {x, 0, lastxhat}, PlotLabel -> "Land rental price per m^2"]
lasth = Plot[{h[x, y, t, lastta, f, lastfa, lastul]}, {x, 0, lastxhat}, PlotLabel -> "Floor to area ratio"]
lastDen = Plot[{Den[x, y, t, lastta, f, lastfa, lastul]*10}, {x, 0, lastxhat}, PlotLabel -> "Population density"]
lastL = Plot[{L[x, y, t, lastta, f, lastfa, lastul]/1000}, {x, 0, lastxhat}, PlotLabel -> "Population (1000s)"]

ResourceFunction["PlotGrid"][{
{Show[basep, lastp, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseq, lastq, PlotRange -> {{0, 25}, {73, 78}},
AxesOrigin -> {0, 0}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]},
{Show[baser, lastr, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseh, lasth, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]},
{Show[baseDen, lastDen, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseL, lastL, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]}}]


And I get this beautiful grid:

Except the labels are in odd locations. How do I move them within the graphs?

• In each Plot use Epilog option to add Text where you want it. Sep 29, 2022 at 13:35
• @BobHanlon In one of the graphs I have two Epilogs: (how do I show this as code?) Epilog -> {Dashed, LightBlue, Line[{{basexhat, 0}, {basexhat, 600}}], Dashed, LightBlue, Line[{{lastxhat, 0}, {lastxhat, 600}}]}] Do I add a new Epilog after I or do I write it inside the {} or outside the {}? Sep 29, 2022 at 13:43
• You only need one Epilog per Plot, it can contain everything. Epilog -> {Text[lbl, pos], ...} Sep 29, 2022 at 13:47
• Similar to 153339.
– Syed
Sep 29, 2022 at 13:59
• @BobHanlon That worked. Is there a way I can change the font to be the same as the PlotLabel in terms of font, size and color? Sep 29, 2022 at 14:05

## 1 Answer

In addition to the Epilog based solution suggested by @BobHanlon in the comments, ResourceFunction["PlotGrid"] also supports labeling via the PlotLabels option and Labeled wrappers:

First, your plots with some dummy functions:

basexhat = 25;
lastxhat = 20;

basep = Plot[{x*150}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]}];
baseq = Plot[{x}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]}];
baser = Plot[{x*150}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]}];
baseh = Plot[{x}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]}];
baseDen = Plot[{x*10}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]}];
baseL = Plot[{x/1000}, {x, 0, basexhat}, PlotStyle -> {Opacity[0.5]},
Epilog -> {Dashed, LightBlue,
Line[{{basexhat, 0}, {basexhat, 600}}], Dashed, LightBlue,
Line[{{lastxhat, 0}, {lastxhat, 600}}]}];
lastp = Plot[{2 + x*150}, {x, 0, lastxhat}];
lastq = Plot[{2 + x}, {x, 0, lastxhat}];
lastr = Plot[{2 + x*150}, {x, 0, lastxhat}];
lasth = Plot[{2 + x}, {x, 0, lastxhat}];
lastDen = Plot[{2 + x*10}, {x, 0, lastxhat}];
lastL = Plot[{2 + x/1000}, {x, 0, lastxhat}];

grid = {{
Show[basep, lastp, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseq, lastq, PlotRange -> {{0, 25}, {73, 78}},
AxesOrigin -> {0, 0}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]
}, {
Show[baser, lastr, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseh, lasth, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]
}, {
Show[baseDen, lastDen, PlotRange -> {{0, 25}, All}, Frame -> True],
Show[baseL, lastL, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}]
}};


You can now add labels to the plots by specifying them via the PlotLabels option:

ResourceFunction["PlotGrid"][grid,
PlotLabels -> {"Rental price per m^2", "Dwelling size",
"Land rental price per m^2", "Floor to area ratio",
"Population density", "Population (1000s)"}
]


This puts them into the default position which is {Left,Top}. To put them into the center, use a Placed wrapper:

ResourceFunction["PlotGrid"][
grid,
PlotLabels ->
Placed[{"Rental price per m^2", "Dwelling size",
"Land rental price per m^2", "Floor to area ratio",
"Population density", "Population (1000s)"}, {Center, Top}],
LabelStyle -> {Red, FontSize -> 14}
]


Notice how I have also applied a custom style via the LabelStyle option.

Finally, you can also used Labeled[plot, label, position] for the indiviual plots to specify the labels:

ResourceFunction["PlotGrid"][{
{
Labeled[
Show[basep, lastp, PlotRange -> {{0, 25}, All}, Frame -> True],
"Rental price per m^2", {Center, Top}],
Labeled[
Show[baseq, lastq, PlotRange -> {{0, 25}, {73, 78}},
AxesOrigin -> {0, 0}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}],
"Dwelling size", {Center, Top}]
}, {
Labeled[
Show[baser, lastr, PlotRange -> {{0, 25}, All}, Frame -> True],
"Land rental price per m^2", {Center, Top}],
Labeled[
Show[baseh, lasth, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}],
"Floor to area ratio", {Center, Top}]
}, {
Labeled[
Show[baseDen, lastDen, PlotRange -> {{0, 25}, All},
Frame -> True], "Population density", {Center, Top}],
Labeled[
Show[baseL, lastL, PlotRange -> {{0, 25}, All}, Frame -> True,
FrameTicks -> {{None, All}, {None, None}}],
"Population (1000s)", {Center, Top}]
}},
LabelStyle -> {Red, FontSize -> 14}
]

(* same result *)


(Notice how every Show[...] expression is wrapped in a Labeled expression with the appropriate label and position specified)