Message Boards Message Boards

GROUPS:

How do I make a frame around a PlotLegend?

Posted 1 year ago
2563 Views
|
8 Replies
|
2 Total Likes
|

I apologize in advance because this must be trivial, but I cannot figure out how to get a frame or border around my PlotLegend. Here is the line in Plot

PlotLegends -> {Placed[{"q", "q/a"}, {0.8, 0.9}]}

I tried using LegendFunction -> Framed anywhere I could put it, all it did is print a legend called "LegendFunction -> Framed" .

Generally , if something is the least bit tricky, I find the solution with an internet search, so this must be obvious, but if someone can take me out of my misery I would be most grateful.

--aryeh

8 Replies

Hi there! Can you post an image of the output in Mathematica? I need to see your whole code to help you

Posted 1 year ago

Thank you for your quick response. I added that part of the notebook as a code sample. I think that it will generate the plot in question. When posting a code segment like this, is there a way to run it so that the output is also attached? Best regards --aryeh

`Manipulate[
 pl5 = plotType[{(x ) (1/q)/Sqrt[(1 - (x)^2 )^2 + (x)^2 (1/q)^2   ],
    (x ) (1/q)/Sqrt[(1 - (x)^2 )^2 + (x)^2 (a/q)^2   ]}, {x, 
    lowerLimit, upperLimit}, 
   GridLines -> {{{1, {Thick, Red}}, {1 - 1/(2 q), {Blue, Thick, 
        Dashed}}, {1 + 1/(2 q), {Blue, Thick, Dashed}},
       {1 - a /(2 q), {Green, Thick, Dashed}}, {1 + a/(2 q), {Green, 
        Thick, Dashed}}}, { {1/Sqrt[2], {Thick, Red}}}}, 
   PlotRange -> {{lowerLimit, upperLimit}, {0, 1}},
   LabelStyle -> {FontSize -> 16, FontFamily -> "Times", Black, 
     Bold},
   PlotLegends -> {Placed[{Row[{"Q=", q}], Row[{"Q=", q/a}]}, {0.8, 
       0.9}]},
   PlotStyle -> {Blue, Green}, Frame -> True,  
   FrameLabel -> {None, 
     "\!\(\*SubscriptBox[\(V\), \(R\)]\)/\!\(\*SubscriptBox[\(V\), \
\(IN\)]\)"}];
 pl6 = plotType[{1/Sqrt[(1 - (x)^2 )^2 + (x)^2 (1/q)^2   ],
    1/Sqrt[(1 - (x)^2 )^2 + (x)^2 (a/q)^2   ]}, {x, lowerLimit, 
    upperLimit}, 
   GridLines -> {{{1, {Thick, Red}}, {1 - 1/(2 q), {Blue, Thick, 
        Dashed}}, {1 + 1/(2 q), {Blue, Thick, Dashed}},
       {1 - a /(2 q), {Green, Thick, Dashed}}, {1 + a/(2 q), {Green, 
        Thick, Dashed}}}, { {1/Sqrt[2], {Thick, Red}}}}, 
   PlotRange -> {{lowerLimit, upperLimit}, {0, q}},
   LabelStyle -> {FontSize -> 16, FontFamily -> "Times", Black, 
     Bold},
   PlotLegends -> {Placed[{Row[{"Q=", q}], Row[{"Q=", q/a}]}, {0.8, 
       0.9}]},
   PlotStyle -> {Blue, Green}, Frame -> True,  
   FrameLabel -> {None, 
     "\!\(\*SubscriptBox[\(V\), \(C\)]\)/\!\(\*SubscriptBox[\(V\), \
\(IN\)]\)" }];
 pl7 = plotType[{x^2/Sqrt[(1 - (x)^2 )^2 + (x)^2 (1/q)^2   ],
    x^2/Sqrt[(1 - (x)^2 )^2 + (x)^2 (a/q)^2   ]}, {x, lowerLimit, 
    upperLimit}, 
   GridLines -> {{{1, {Thick, Red}}, {1 - 1/(2 q), {Blue, Thick, 
        Dashed}}, {1 + 1/(2 q), {Blue, Thick, Dashed}},
       {1 - a /(2 q), {Green, Thick, Dashed}}, {1 + a/(2 q), {Green, 
        Thick, Dashed}}}, { {1/Sqrt[2], {Thick, Red}}}}, 
   PlotRange -> {{lowerLimit, upperLimit}, {0, q}},
   LabelStyle -> {FontSize -> 16, FontFamily -> "Times", Black, 
     Bold},
   PlotLegends -> {Placed[{Row[{"Q=", q}], Row[{"Q=", q/a}]}, {0.8, 
       0.9}]},
   PlotStyle -> {Blue, Green}, Frame -> True,  
   FrameLabel -> {"NORMALIZED FREQUENCY", 
     "\!\(\*SubscriptBox[\(V\), \(L\)]\)/\!\(\*SubscriptBox[\(V\), \
\(IN\)]\)" }];
  GraphicsGrid[{{pl5}, {pl6}, {pl7}}, ImageSize -> {750, 1500}],
 {{q, 5}, 0.25, 50}, {{a, 5}, 0.1, 
  50}, {plotType, {LogLinearPlot, Plot}}, {{upperLimit, 100}, {1.2, 
   1.5, 2, 5, 10, 100}}, {{lowerLimit, 0.01}, {0.01, 0.1, 0.5, 0.8}},


 SaveDefinitions -> True]`

Hi Aryeh, the code looks fine to me. What version of Mathematica are you using? In this situation, by Occam's razor, I will say to you that you need to install the package PlotLegend. if it is installed then try to use the option LegendBorder in PlotLegend instead of Frame. Tell me if this works for you.

Kind regards

Posted 1 year ago

I am using Mathematica 12. PlotLegend is listed as obsolete, and its functionality is supposed to be built in. I am worried about having a package that may conflict with built in functions. I think I need to learn how to use LegendFunction -> Framed but I cannot figure out where to put it in PlotLegend.

Posted 1 year ago

Got it. The following code works, though I think that there must be an easier way.

PlotLegends -> 
 Placed[LineLegend[{Blue, Green}, {Row[{"Q=", q}], Row[{"Q=", q/a}]}, 
   LegendFunction -> Framed], {0.8, 0.9}],

Nice to hear that.

Hi Aryeh,

There is no need to duplicate the colors

PlotLegends -> 
  Placed[LineLegend[{Row[{"Q=", q}], Row[{"Q=", q/a}]}, 
    LegendFunction -> "Frame"], {Right, Top}]]
Posted 1 year ago

Thank you. That works, and {Right, Top} is better than my absolute placement.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract