title: How can I plot the margins in a python bode plot?
body: <p>I want to plot a bode plot of a system with the python control systems library. This is fairly easy. The problem is the plot of the margins. It is no problem to plot the phase margin. But how can I plot the gain margin?</p>
  
  <p>So far, this is a part of my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import control as cn
  %matplotlib notebook
  import matplotlib.pyplot as plt
  
  Ks=2
  T1=5
  T2=0.3
  T3=0.1
  Gs=cn.tf(Ks,[T1*T2*T3, T1*T2+T1*T3+T2*T3, T1+T2+T3, 1])
  
  Vr=1
  Tn=1
  plt.close()
  R=cn.tf([Vr*Tn, Vr],[1, 0])
  L=Gs*R
  gm, pm, wg, wp = cn.margin(L)
  
  _,_,_ = cn.bode(L,dB=True)
  plt.axvline(x = wp,color='r')
  </code></pre>