title: rotating the z-axis in matplotlib 3d figure
body: <p>How do I rotate the z-axis of a matplotlib figure so that it appears as the horizontal axis? I have created the following 3d figure :
  <a href="https://i.stack.imgur.com/2BSPY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2BSPY.png" alt="enter image description here"></a></p>
  
  <p>I tried adjusting the values in </p>
  
  <blockquote>
    <p>ax.view_init()
    but no matter what values I used, I can't flip the z-axis so that the orientation of the three axes appear as like the ones in the following figure:
    <a href="https://i.stack.imgur.com/zPS87.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zPS87.png" alt="enter image description here"></a> </p>
  </blockquote>
  
  <p>I thought of changing the three components of all the data so that I use the x-axis to plot the z-component of the data, but then it will be very inconvenient to many of my calculations, and more importantly, I don't know how to use ax.set_aspect to keep the whole figure in the same scale in a rectangular box (rectangular because the (original) z-component of the data usually spans a larger range than the x and y components).</p>
  
  <p>So how do I rotate the z-axis (by 90 deg)?</p>
  
  <p>EDIT:</p>
  
  <p>Just to clarify my question. Using the example used in the answer, I have the following code that can generate a figure that has the SAME scale in all three axes, and even if I resize the pop-out window, the figure still has the same aspect ratio for the three axes and look the same. This is what I want, but with the z-axis rotated by 90deg so it appears horizontal (the desired coordinate system look like the one shown in the above figure of EM wave). If I switch the plotting order of the three axes, I do get a horizontal z-axis (which is plotted as the x-axis), but then I can't use the ax.set_aspect to change the scale.</p>
  
  <pre><code>from mpl_toolkits.mplot3d import axes3d
  import matplotlib.pyplot as plt
  import numpy as np
  
  fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  X, Y, Z = axes3d.get_test_data(0.05)
  ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
  ax.set_xlim(-30,30)
  ax.set_ylim(-30,30)
  ax.set_zlim(-90,90)
  ax.set_aspect(3, 'box-forced')
  plt.show()
  </code></pre>