1
$\begingroup$

I am having a problem placing my legend inside a bode plot (magnitude or phase - any would do). I cannot find any command that lets me do so.

My command for bode plot is

BodePlot[TF[2 \[Pi] s], {0.001, 100}, 
PhaseRange -> {-\[Pi], \[Pi]}, 
PlotStyle -> {Thickness[0.01], Thickness[0.008], Thickness[0.005]}, 
GridLines -> Automatic, 
PlotLegends -> {"\!\(\*SubscriptBox[\(\[ScriptCapitalP]\), \(1\)]\)",
"\!\(\*SubscriptBox[\(\[ScriptCapitalP]\), \(2\)]\)", 
"\!\(\*SubscriptBox[\(\[ScriptCapitalP]\), \(3\)]\)"}, 
PlotLabel -> {"Impulse Response Function \!\(\*SubscriptBox[\(\
\[ScriptCapitalP]\), \(i\)]\)(s)", ""}, 
FrameLabel -> {{"Frequency [Hz]", 
"Magnitude [dB]"}, {"Frequency [Hz]", "Phase [deg]"}}, 
BaseStyle -> {FontSize -> 20, FontSize -> 20}, ImageSize -> Large]

Here, TF is a TransferFunctionModel.

I want to put the legends inside the bode plot environment rather than it occurring on the side.

$\endgroup$

1 Answer 1

4
$\begingroup$

The PlotLegends option in BodePlot is not used to label the magnitude and phase. Instead, you use PlotLegends whenever you plot more than one function in the same call of BodePlot. If you want to label the magnitude and phase plots, you can use PlotLabel:

BodePlot[
  {
   TransferFunctionModel[{{{20}}, 20 + s}, s], 
   TransferFunctionModel[{{{10}}, 15 + 2 s}, s]
  },
  PlotLegends -> {
    "\!\(\*SubscriptBox[\(\[ScriptCapitalP]\), \(1\)]\)",
    "\!\(\*SubscriptBox[\(\[ScriptCapitalP]\), \(2\)]\)"
  },
  PlotLabel -> {"Magnitude Plot", "Phase Plot"}
]

Edit If you want a legend inside of the plot, you can use Epilog and LineLegend:

BodePlot[
  TransferFunctionModel[{{{20}}, 20 + s}, s], 
  Epilog -> {
    Inset[LineLegend[{Blue}, {"Amplitude"}], {1, -15}], 
    Inset[LineLegend[{Blue}, {"Phase"}], {1, -60}]
  }
]
$\endgroup$
3
  • $\begingroup$ I may not have been clear with my question. I want to put the legends inside the bode plot environment rather than it occurring on the side. Thanks for the interest though! $\endgroup$
    – Zero
    Commented Oct 5, 2016 at 11:12
  • $\begingroup$ Ah, I am sorry for misunderstanding you. In that case, you should use Epilog and LineLegend. Let me update the answer accordingly. $\endgroup$ Commented Oct 5, 2016 at 12:19
  • $\begingroup$ Great job...thanks :) $\endgroup$
    – Zero
    Commented Oct 5, 2016 at 13:29

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.