# How to combine plots together and add legends inside the frame?

I want to combine the Zenga curves of a distribution, for different parameter values. For each curve, the parameters are a, p, q. The values for the four curves are "a = 3, p = .1, q = 5"," a = 2, p = 5, q = 0.6 ","a = 4, p = 0.5, q = 0.6", and " a = 4, p = 2, q = 2".

c = 1 - 1/a;
x = 1 + 1/a;
y = q - 1/a;
z = p + 1/a;
Z[a_, p_, q_] := ( q*(Beta[x, y] - u^-1*Beta[1 - (1 - u)^(1/q), x, y]) + p*(Beta[z, c] u^-1*Beta[u^(1/p), z, c]))/(q*(Beta[x, y] - Beta[1 - (1 - u)^(1/q), x, y]) +
p*(Beta[z, c] - Beta[u^(1/p), z, c])) ##Zenga curve

z1 = Plot[Z[3, .1, 5], {u, 0, 1}, PlotStyle -> Directive[ColorData[97][1], Dashed],
PlotRange -> {{0, 1}, {0.3, 1}}]

z2 = Plot[Z[2, 5, .6], {u, 0, 1}, PlotStyle -> Directive[ColorData[97][2], DotDashed],
PlotRange -> {{0, 1}, {0.3, 1}}]

z3 = Plot[Z[4, .5, .6], {u, 0, 1}, PlotStyle -> Directive[ColorData[97][3], Dashing[Large]],
PlotRange -> {{0, 1}, {0.3, 1}}]

z4 = Plot[Z[4, 2, 2], {u, 0, 1}, PlotStyle -> Directive[ColorData[97][4], Dotted],
PlotRange -> {{0, 1}, {0.3, 1}}]

Legended[Show[z1, z2, z3, z4, Frame -> True, FrameLabel -> {{"Z(u)", None}, {"u", None}}, ImageSize -> 400], LineLegend[ColorData[97] /@ {1, 2, 3, 4}, {"a=3,p=.1,q=5", "a=2,p=5,q=0.6",
"a=4,p=0.5,q=0.6", "a=4,p=2,q=2"}]]


I combined the plots using the last command and got an output as shown (Legend section is not able to download) below. How can I put legends inside the frame? How can I add dashes and dots in legends?

• Define Legends in every single plot, Show combines them automatically! Commented Sep 13, 2023 at 17:30
• You can use Placed as in Placed[LineLegend[. . .],{xCoord,yCoord}] with xCoord and yCoord absolute coordinates. Look up Placed command. Good start is to use {0.8,0.8} as the location. May need to experiment with location.
– josh
Commented Sep 13, 2023 at 17:56

You can eliminate a lot of redundant code by using a single Plot

\$Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global*"]

c = 1 - 1/a;
x = 1 + 1/a;
y = q - 1/a;
z = p + 1/a;
Z[a_, p_,
q_] = (q*(Beta[x, y] - u^-1*Beta[1 - (1 - u)^(1/q), x, y]) +
p*(Beta[z, c] u^-1*Beta[u^(1/p), z, c]))/(q*(Beta[x, y] -
Beta[1 - (1 - u)^(1/q), x, y]) +
p*(Beta[z, c] - Beta[u^(1/p), z, c])) // Simplify;

apqValues = {{3, .1, 5}, {2, 5, .6}, {4, .5, .6}, {4, 2, 2}};

Plot[Evaluate[Z @@@ apqValues], {u, 0, 1},
PlotStyle -> {Dashed, DotDashed, Dashing[Large], Dotted},
PlotRange -> {{0, 1}, {0.3, 1}},
Frame -> True,
FrameLabel -> (Style[#, 14] & /@ {HoldForm[u], HoldForm[Z[u]]}),
PlotLegends -> Placed[(
StringForm["a=,\[ThinSpace]p=,\[ThinSpace]q=", ##] & @@@ apqValues
), {.83, .2}],
ImageSize -> 500]
`

• Both graphs look different. I already plotted z1,z2,z3 and z4 seperately and found its range. Moreover, the Zenga curve lies between 0 and 1. Commented Sep 14, 2023 at 6:49
• I'm not familiar with what a Zenga curve is. You should check the formulas that you posted. Commented Sep 14, 2023 at 14:00