3d plots with aspect=’equal’

aspect='equal' argument is completely misused by axes3D.
To verify:

import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
fig = plt.figure()
ax = fig.add_subplot((111), aspect='equal', projection='3d')
ax.scatter((1, 2), (1, 1.2), (1, 2)) 
  • The figure is rendered with all axes scaled to the data scale, thus ignoring the aspect setting.
  • If one tries to rotate the figure, using GUI, it is rescaled to fix into a very uneven rectangle, presumably calculated from x-scale vs y-scale, and hence with aspect ratio 1:5.

Author: Fantashit

8 thoughts on “3d plots with aspect=’equal’

  1. Why doesn’t it make sense? If I want to e.g. mark coordinates in a building, or any system where three axes have the same dimension, I do want that the same axes is chosen for each of the axes (that’s where I actually encountered the bug). And of course regardless of that, the current handling is bugged.

  2. We also came across this issue – if I run the following code:

    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    from itertools import product, combinations
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1,projection='3d')
    
    #draw cube
    r = [-1, 1]
    for s, e in combinations(np.array(list(product(r,r,r))), 2):
        if np.sum(np.abs(s-e)) == r[1]-r[0]:
            ax.plot3D(*zip(s,e), color="b")
    

    I get:

    cube

    and adding

    ax.set_aspect('equal')
    

    then gives

    cube_equal

    which is simply wrong, not just sub-optimal. The cube lines should always be parallel to the axes. In my opinion, it should look more like

    cube_shouldbe

    But at the very least, if set_aspect('equal') is going to do the wrong thing, it would be better if it raised a NotImplemented error.

    (this issue was originally pointed out to me by @koepferl)

  3. My research entails lots of 3D plotting on unit spheres. Needless to say, a unit sphere is a perfect sphere and to display it properly all axes need to have the same scale. This is another use case that requires this functionality.

    I would love to help out, but don’t have the time to dig into the code right now. I really hope this feature gets some priority for future releases.

  4. @dstansby My vote is for a NotImplementedError. This is a dangerous footgun and should not be allowed as long as it’s not actually implemented.

  5. With regard to the objection that we can’t have “aspect equal” without requiring a specific projection, I’d like to point out that under any projection a sphere looks like a circle, which should sufficiently define “aspect equal” in any case.

  6. @jklymak what do you mean by the non-optimal behavior? Does closing this issue mean that 3D plots with equal aspect ratio aren’t on the roadmap?

Comments are closed.