By default, plotting a set of points (or whatever) in 3D with matplotlib
, locates the z
axis vertically, as seen here (code below):
I need to interchange the z
and y
axis, so that that y
axis is shown vertically.
I've looked around but found no way to tell matplotlib
to do this.
Add: I do not want to have to resort to a hack where I interchange the data and labels. This is a simple 3 points 3D plot, but I have to plot much more complicated surfaces. I'm looking for a general solution, not just something that works with scatter plots. A simple way to tell matplotlib
to put the y
axis vertically instead of the z
axis is the clean way to do it.
MWE
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter([0.2, 0.5, 0.8], [2.3, 0.47, 1.], [2.1, 5.3, 0.7])
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
Matplotlib 3.6.0 is now out, and allows you to set this third view angle via the command ax.view_init(elev, azim, roll)
. See the official documentation.