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.
an “aspect” kwarg doesn’t make a lot of sense for 3d plots, which is why even matlab doesn’t do it. I have an old branch that provides some very basic functionality in this direction, but I never finished. See here:
http://matplotlib.1069221.n5.nabble.com/mplot3d-and-daspect-tp11521p11523.html
PRs against this branch would be welcomed!
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.
We also came across this issue – if I run the following code:
I get:
and adding
then gives
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
But at the very least, if
set_aspect('equal')
is going to do the wrong thing, it would be better if it raised aNotImplemented
error.(this issue was originally pointed out to me by @koepferl)
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.
I’ve also come across a number of stack overflow posts about this:
@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.
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.
@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?