You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
Reacted by Samuel Ainsworth, Peter Dijkstra, Alex, chuyicui, barabanus, Javier Dehesa, Daniel Soutar, Morten Lind, Coelancanth, Tal Golan and 48 more
Reacted by Roman Kovtyukh, Tim, Rafael de la Fuente Herrezuelo, Pan Yu and BUGMAN
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:
and adding
ax.set_aspect('equal')
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 a NotImplemented error.
(this issue was originally pointed out to me by @koepferl)
Reacted by Andrew, Juan Luis Cano Rodríguez, Nick LaFarge, Samuel Ainsworth, Peter Dijkstra, Mateen Ulhaq, Jonathan King, darkdragon-001, barabanus, Daniel Soutar and 13 more
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.
Reacted by Mateen Ulhaq, barabanus, chtapodi, Thomas Mansencal, Juliano Ferrari Gianlupi, Jacek Grzybowski, RachelChen, Max Schwendeler, laurap81, ZhouWJ and 7 more
Actually there are several ways of showing a 3D model on a 2D screen, mainly including axonometric projection and perspective projection. There are also many kinds of axonometric projections. So even the unit length of three axises are the same, they look different on the screen on many circumstances. A cubic box may look not that cubic if drawn in different ways. So if the 3D plot class is to be improved, projection method should be determined beforehand.
@Hanlin-Dong I agree, but no matter how the projection is done, the projection for the data must match the projection for the axes. In the example above it doesn't, hence the bug report. Also the bug report isn't about the projection as much as the impossibility to correctly set the aspect ratios.
I also think that this feature is quite important for 3d plots.
True, it might not be that important if you visualize data without
an underlying real-world geometry. But I have to visualize the
heat distribution on motor parts in 3D and this looks quite strange if the
aspect ratio is incorrect. I guess the same it true with the buildings that @akhmerov mentioned.
I hope he is closing because of (still open) #8896 just to clean the issue tracker, as #13474 is only a workaround on how to deal with the behaviour until it is implemented.
If setting this with a string is important please open a new issue with what you would expect "equal" to do under various conditions / adjustable settings.
The code that would need to be changed to implement this is
It is not obvious to me what the correct heuristics are to adjust the data limits / box aspect are under the different adjustable regimes (or if the adjustable values should be the same as in 2D?).
I suspect that this is 10-30 (apply the standard factor of pi, but would also be very happy to be over estimating) hours of work (most of it reading the mplot3d code) to implement for someone who knows Python well.
Activity
WeatherGod commentedon Aug 20, 2012
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!
akhmerov commentedon Aug 20, 2012
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.
vallettea commentedon Jan 23, 2013
I would also be interested by this feature.
By the way, did you found a way to tackle the problem?
astrofrog commentedon Feb 24, 2013
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 aNotImplementederror.(this issue was originally pointed out to me by @koepferl)
tehingo commentedon Mar 25, 2013
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.
akhmerov commentedon Mar 25, 2013
Just in case somebody encounters this bug, and needs a workaround: the way I handle this is by manually calling ax.auto_scale_xyz before rendering.
Hanlin-Dong commentedon Jan 6, 2016
Actually there are several ways of showing a 3D model on a 2D screen, mainly including axonometric projection and perspective projection. There are also many kinds of axonometric projections. So even the unit length of three axises are the same, they look different on the screen on many circumstances. A cubic box may look not that cubic if drawn in different ways. So if the 3D plot class is to be improved, projection method should be determined beforehand.
akhmerov commentedon Jan 6, 2016
@Hanlin-Dong I agree, but no matter how the projection is done, the projection for the data must match the projection for the axes. In the example above it doesn't, hence the bug report. Also the bug report isn't about the projection as much as the impossibility to correctly set the aspect ratios.
solarjoe commentedon Jan 18, 2016
I also think that this feature is quite important for 3d plots.
True, it might not be that important if you visualize data without
an underlying real-world geometry. But I have to visualize the
heat distribution on motor parts in 3D and this looks quite strange if the
aspect ratio is incorrect. I guess the same it true with the buildings that
@akhmerov mentioned.
@WeatherGod mentioned above that Matlab does not provide this feature, but
I am quite sure it does.
This is the manpage, it also shows 3D examples for "normal" and "equal".
http://de.mathworks.com/help/matlab/creating_plots/aspect-ratio-for-2-d-axes.html
More information on how it is implemented as axis property:
http://de.mathworks.com/help/matlab/ref/axes-properties.html#prop_DataAspectRatio
I guess most of it is already implemented and working in matplotlib but I came across
a small issue, see my post and example code in #1104.
samuela commentedon May 6, 2018
I just got this plot after calling
ax.set_aspect('equal'). Definitely not equal based on the ticks!timhoffm commentedon May 6, 2018
Related and possibly a first step for fixing this: #8896
11 remaining items
jklymak commentedon Mar 3, 2019
Closing due to #13474 and the fact that the non-optimal behaviour is discussed in previous issues and PRs references above...
akhmerov commentedon Mar 3, 2019
@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?
solarjoe commentedon Mar 3, 2019
I hope he is closing because of (still open) #8896 just to clean the issue tracker, as #13474 is only a workaround on how to deal with the behaviour until it is implemented.
jklymak commentedon Mar 3, 2019
Correct. OTOH I don't know of anyone actively developing mplot3d, so if someone wants this feature, it would require a volunteer..
zh-plus commentedon Aug 14, 2019
solarjoe commentedon Aug 14, 2019
The original link is https://stackoverflow.com/questions/13685386/matplotlib-equal-unit-length-with-equal-aspect-ratio-z-axis-is-not-equal-to and has already been mentioned above.
Removed dependency on specific matplotlib version
Removed dependency on specific matplotlib version
Fixed the matplotlib 3D set_aspect('equal') issue
jondo commentedon Jun 2, 2021
In order to get a future notification of
aspect='equal'working, which open issue (or unmerged PR) should I subscribe to?tacaswell commentedon Jun 3, 2021
Please see the note at https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.3.0.html#axes3d-no-longer-distorts-the-3d-plot-to-match-the-2d-aspect-ratio (from #17515) for how to get this effect.
If setting this with a string is important please open a new issue with what you would expect "equal" to do under various conditions / adjustable settings.
The code that would need to be changed to implement this is
matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Lines 275 to 347 in a3fbf18
and
matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Lines 407 to 422 in a3fbf18
and likely
matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py
Lines 365 to 405 in a3fbf18
It is not obvious to me what the correct heuristics are to adjust the data limits / box aspect are under the different adjustable regimes (or if the
adjustablevalues should be the same as in 2D?).I suspect that this is 10-30 (apply the standard factor of pi, but would also be very happy to be over estimating) hours of work (most of it reading the mplot3d code) to implement for someone who knows Python well.
tacaswell commentedon Jun 21, 2021
@SirSharpest Can you please explain why the process in https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.3.0.html#axes3d-no-longer-distorts-the-3d-plot-to-match-the-2d-aspect-ratio is insufficient?
logari81 commentedon Aug 2, 2022
all what axis('equal') should do is this:
oscargus commentedon Aug 2, 2022
There is a PR that hopefully will be included in 3.6. #23409