title: In matplotlib, how to use a secondary axis that is input to the function together with the primary axis?
body: <p>I have a function with two arguments (<code>x1</code>, <code>x2</code>). I would like to plot the function with its result on the y axis, <code>x1</code> on the x axis and <code>x2</code> on the right y axis (secondary axis).</p>
  
  <p>My problem is that the values of the <code>x1</code> and <code>x2</code> axes do not correspond together to the function point.</p>
  
  <p>For example: </p>
  
  <p><img src="https://i.stack.imgur.com/60w5m.png" alt="Example chart"></p>
  
  <p>I want the value read on the primary y axis to match the <code>x1</code> and <code>x2</code> inputs of the other two axes.</p>
  
  <p>Code: </p>
  
  <pre><code>x1 = np.linspace(0, 10, 10)
  x2 = np.linspace(0, 5, 10)
  
  f = lambda x1, x2: np.exp(-x1) / 10 + np.exp(-x2) / 10
  
  resp = []
  for i, j in zip(x1, x2):
      resp.append(f(i, j))
  resp = np.array(resp)
  
  fig, ax1 = plt.subplots()
  ax2 = ax1.twinx()
  
  ax1.plot(x1, resp)
  
  ax1.set_xlabel('(x1)')
  ax1.grid(True)
  ax1.set_ylabel('(y)')
  
  ax2.set_ylabel('(x2)')
  ax2.set_yticks(x2)
  
  plt.xticks(np.arange(min(x1), max(x1)))
  
  plt.show()
  </code></pre>