Y and z axis placement location in 3D matplotlib plot

By default, building a set of points (or any other) in 3D with matplotlib defines the z axis vertically, as shown here (code below):

enter image description here

I need to swap the z axis and y axis so that the y axis is shown vertically.

I looked around, but did not find a way to tell matplotlib for this.

Add: I do not want to resort to a hacker, where I change data and tags. This is a simple 3-point 3D plot, but I have to build much more complex surfaces. I am looking for a general solution, not just what works with scatter. An easy way to tell matplotlib put the y axis vertically instead of the z axis is a clean way to do this.


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() 
+13
source share
2 answers

One possibility is to swap y and z in the data and labels, respectively. instead

 ax.scatter([0.2, 0.5, 0.8], [2.3, 0.47, 1.], [2.1, 5.3, 0.7]) 

use

 ax.scatter([0.2, 0.5, 0.8], [2.1, 5.3, 0.7], [2.3, 0.47, 1.]) 

and designate ax.set_ylabel('z') and ax.set_zlabel('y')

+1
source

I do not think this is possible at present. ax.view_init() should also take a third angle. I discovered the problem on github, https://github.com/matplotlib/matplotlib/issues/14453#issue-452397120 , I hope someone is interested in implementing this function.

0
source

All Articles