Uniformly scaled axes in 3d plot with python matplotlib
Question: I'm plotting a set of 3d coordinates (x,y,z) using Axes3D. My code reads

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    x,y,z=data[::1,0],data[::1,1],data[::1,2]
    fig=plt.figure(figsize=(10,10))
    ax=fig.add_subplot(111,projection='3d')
    ax.scatter(x,y,z,s=0.1,c=z,cmap='hot',marker='+')
    plt.show()
    

I want all three axes to have the same scaling. Now, the problem is that the
data has a large aspect ratio, that is, the variation in the x and y
coordinates is about 10 times larger than the variation in the z coordinate.
If I put

    
    
    mi=np.min(data)
    ma=np.max(data)    
    ax.set_xlim(mi,ma)
    ax.set_ylim(mi,ma)
    ax.set_zlim(mi,ma)
    

this will result in uniformly scaled axes but will waste a lot of space in the
z direction. How can I avoid this and get uniformly scaled axes nevertheless?


Answer: There is a question in SO that is similar... but I cannot find it. So I am
attaching some code for what I understand is your problem (the part that
scales is not mine, but from that other post I mentioned)

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    data =np.random.rand(100,3)
    
    x,y,z= 10*data[:,0], 20*data[:,1], 5*data[:,2]
    fig=plt.figure(figsize=(10,10))
    ax=fig.add_subplot(111,projection='3d')
    ax.scatter(x,y,z)
    
    # Fix aspect ratio
    max_range = np.array([x.max()-x.min(), y.max()-y.min(),
                          z.max()-z.min()]).max() / 2.0
    mean_x = x.mean()
    mean_y = y.mean()
    mean_z = z.mean()
    ax.set_xlim(mean_x - max_range, mean_x + max_range)
    ax.set_ylim(mean_y - max_range, mean_y + max_range)
    ax.set_zlim(mean_z - max_range, mean_z + max_range)
    
    plt.show()
    

And, this is the result:

![enter image description here](http://i.stack.imgur.com/u7gPp.png)

