title: How do I create a secondary axis for a second function in matplotlib?
body: <p>I have two functions. Both use the same x axis, but the values for the y axis are too high for one function compared to the other, so one function would just lie flat. How do I create a secondary y axis for the second function so that I can view both functions on one single plot?</p>
  
  <p>This is my code:</p>
  
  <pre><code>import math
  import matplotlib.pyplot as plt
  
  g = 9.81
  vo = 14.5
  zo = 2.35
  m = 7.257
  
  sin = (vo/((2*((vo**2)+g*zo))**(1/2)))
  alpha = math.asin(sin)
  tan = math.tan(alpha)
  
  z= []; x = []; E = []
  for i in range(1000):
      x.append(i*(1/41))
      z.append(-(g/2)*((x[i]**2)/(vo**2))*(1+tan**2)+tan*x[i]+zo)
      E.append(m*g*z[i])
      if len(z)&gt;=3:
          if z[-1]&lt;=0 and z[-2]&gt;0:
              x0 = (x[-1] + x[-2])/2
          if z[-2]&gt;z[-1] and z[-2]&gt;z[-3]:
              zmax=z[-2]
              xmax=x[-2]
  
  
  fig = plt.figure()
  plt.title("Wurf der Kugel")
  plt.ylim(-1,700)
  plt.xlim(0,25)
  plt.xlabel("Distanz in m")
  plt.ylabel("Hoehe in m")
  dotx0=(x0,0)
  dotmax=(xmax,zmax)
  print("Die Wurfweite ist bei {}. Das Maximum ist bei {}".format(dotx0,dotmax))
  plt.plot(x0,0,"o", markersize = 8, label=dotx0)
  plt.plot(xmax,zmax,"o", markersize = 8, label=dotmax)
  plt.grid(True)
  plt.legend()
  plt.plot(x,z)
  plt.plot(x,E)
  
  plt.show()
  </code></pre>
  
  <p>Thanks a lot!</p>