2
$\begingroup$

I use Plot to draw two figures and combine them in one figure with the following code.

C1 = Plot[{((3 t + 1/2)^2 (1 - 2 t 1/4))/(18 t) + 2 t^3 (1)^2 (1/4)^3}, {t, 1/6 (3 - Sqrt[3]), 2}, 
    PlotTheme -> "Scientific", PlotRange -> Automatic, FrameLabel -> {{HoldForm[SubsuperscriptBox["\[Pi]", "i", "*"] // DisplayForm], None}, {HoldForm[t], None}}, 
    LabelStyle -> {GrayLevel[0]}, PlotStyle -> {Red}, 
    PlotLegends -> {"\!\(\*SubsuperscriptBox[\(\[Pi]\), \(A\), \(*\)]\) \under \!\(\*SubscriptBox[\(\[Alpha]\), \(A\)]\)=1"}]

D1 = Plot[{((3 t - 1/2)^2 (1 - 2 t (1/4)))/(18 t) + 2 t^3 (1)^2 (1/4)^3}, {t, (1/6) (3 - \[Sqrt]3), 2}, 
    PlotTheme -> "Scientific", PlotRange -> Automatic, FrameLabel -> {{HoldForm[SubsuperscriptBox["\[Pi]", "i", "*"] // DisplayForm], None}, {HoldForm[t], None}}, PlotStyle -> {Dashed, Red}, 
    PlotLegends -> {"\!\(\*SubsuperscriptBox[\(\[Pi]\), \(B\), \(*\)]\) \under \!\(\*SubscriptBox[\(\[Alpha]\), \(B\)]\)=1"}]

Show[C1, D1, PlotRange -> All]

However, the font styles of the plot legend are different as shown in the picture even if I used the same PlotLegends in the code and I have tried LegendMaker and autoLegendto make the legend look nice but failed. Result Figure with Plot Legends How can I adjust or rewrite the code to make the plot legends look the same or achieve the effect of autoplot putting the legends on the right-bottom side of the figure? Thanks in advance.

In addition, how can I put the plot legend in the rounded rectangle with a grey background-color as shown in the example picture below?

example picture

$\endgroup$

2 Answers 2

3
$\begingroup$

An alternative that allows to put the legend in the lower right corner (or everywhere for that matter):

Plot[{((3 t + 1/2)^2 (1 - 2 t 1/4))/(18 t) + 
   2 t^3 (1)^2 (1/4)^3, ((3 t - 1/2)^2 (1 - 2 t (1/4)))/(18 t) + 
   2 t^3 (1)^2 (1/4)^3}, {t, 1/6 (3 - Sqrt[3]), 2}, 
 PlotTheme -> "Scientific", PlotRange -> All, 
 FrameLabel -> {HoldForm[t], 
   HoldForm[SubsuperscriptBox["\[Pi]", "i", "*"] // DisplayForm]}, 
 PlotStyle -> {Red, {Dashed, Red}},
 PlotLegends -> 
  Placed[LineLegend[{"\!\(\*SubsuperscriptBox[\(\[Pi]\), \(A\), \
\(*\)]\) under \!\(\*SubscriptBox[\(\[Alpha]\), \(A\)]\)=1", 
     "\!\(\*SubsuperscriptBox[\(\[Pi]\), \(B\), \(*\)]\) under \
\!\(\*SubscriptBox[\(\[Alpha]\), \(B\)]\)=1"}, 
    LegendLayout -> 
     Function[{x}, Grid[x, Spacings -> {0.6, 0}, Alignment -> Left]], 
    LegendMarkerSize -> {22, 12}], {0.8, 0.2}]]

enter image description here

The last parenthesis in the Placed command controls where you want the legend to appear.

To add a box around the legend, as requested in the comments, use:

Plot[{((3 t + 1/2)^2 (1 - 2 t 1/4))/(18 t) + 
   2 t^3 (1)^2 (1/4)^3, ((3 t - 1/2)^2 (1 - 2 t (1/4)))/(18 t) + 
   2 t^3 (1)^2 (1/4)^3}, {t, 1/6 (3 - Sqrt[3]), 2}, 
 PlotTheme -> "Scientific", PlotRange -> All, 
 FrameLabel -> {HoldForm[t], 
   HoldForm[SubsuperscriptBox["\[Pi]", "i", "*"] // DisplayForm]}, 
 PlotStyle -> {Red, {Dashed, Red}}, 
 PlotLegends -> 
  Placed[LineLegend[{"\!\(\*SubsuperscriptBox[\(\[Pi]\), \(A\), \
\(*\)]\) under \!\(\*SubscriptBox[\(\[Alpha]\), \(A\)]\)=1", 
     "\!\(\*SubsuperscriptBox[\(\[Pi]\), \(B\), \(*\)]\) under \
\!\(\*SubscriptBox[\(\[Alpha]\), \(B\)]\)=1"}, 
    LegendLayout -> 
     Function[{x}, Grid[x, Spacings -> {0.6, 0}, Alignment -> Left]], 
    LegendMarkerSize -> {22, 12}, 
    LegendFunction -> (Framed[#, 
        FrameStyle -> Directive[Thickness[.05]], RoundingRadius -> 4, 
        Background -> RGBColor[.95, .95, .95, 1]] &)], {0.75, 0.2}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ LegendLayout Function is useful to adjust the plot legend, but I still want to put the legends into a rounded rectangle with a grey background color as shown in the picture added later. Do you have a good idea to realize this? Thx $\endgroup$
    – Jay Zhang
    Commented Dec 15, 2020 at 7:12
2
$\begingroup$

Use a single Plot

Clear["Global`*"]

Plot[{
  ((3 t + 1/2)^2 (1 - 2 t 1/4))/(18 t) + 2 t^3 (1)^2 (1/4)^3,
  ((3 t - 1/2)^2 (1 - 2 t (1/4)))/(18 t) + 2 t^3 (1)^2 (1/4)^3}, {t, 
  1/6 (3 - Sqrt[3]), 2},
 PlotTheme -> "Scientific",
 PlotRange -> All,
 FrameLabel -> {HoldForm[t],
   HoldForm[SubsuperscriptBox["π", "i", "*"] // DisplayForm]},
 PlotStyle -> {Red, {Dashed, Red}},
 PlotLegends -> {
   "\!\(\*SubsuperscriptBox[\(π\), \(A\), \(*\)]\) under \
\!\(\*SubscriptBox[\(α\), \(A\)]\)=1",
   "\!\(\*SubsuperscriptBox[\(π\), \(B\), \(*\)]\) under \
\!\(\*SubscriptBox[\(α\), \(B\)]\)=1"}]

enter image description here

$\endgroup$

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.