4
$\begingroup$

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)enter image description here below. How can I put legends inside the frame? How can I add dashes and dots in legends?

$\endgroup$
2
  • 5
    $\begingroup$ Define Legends in every single plot, Show combines them automatically! $\endgroup$ Commented Sep 13, 2023 at 17:30
  • $\begingroup$ 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. $\endgroup$
    – josh
    Commented Sep 13, 2023 at 17:56

1 Answer 1

6
$\begingroup$

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]

enter image description here

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$
    – ASHLIN
    Commented Sep 14, 2023 at 6:49
  • $\begingroup$ I'm not familiar with what a Zenga curve is. You should check the formulas that you posted. $\endgroup$
    – Bob Hanlon
    Commented Sep 14, 2023 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.