-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
3d plots with aspect='equal' #1077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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. |
I would also be interested by this feature. |
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 (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. |
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. |
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 @WeatherGod mentioned above that Matlab does not provide this feature, but I guess most of it is already implemented and working in matplotlib but I came across |
Related and possibly a first step for fixing this: #8896 |
I've also heard that there's a proposed fix (workaround?) in this branch: https://github.com/WeatherGod/matplotlib/tree/mplot3d/pbaspect. Not sure what the status of that is. |
cc @nfoti |
Just thought I'd chime in with my own SO post. As shown below, a square does not look like a square: |
Given that setting aspect to 'equal' doesn't work on 3D axes at the moment, would a sensible course of action in the meantime be to at least raise a warning, and maybe a not implemented error when the user attempts to set a 3D axes to |
👍 a warning would be reasonable and sufficient. |
@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. |
Closing due to #13474 and the fact that the non-optimal behaviour is discussed in previous issues and PRs references above... |
This comment has been minimized.
This comment has been minimized.
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. |
* Method set_aspect('equal') does not work in latest version of 'matplotlib' * See: matplotlib/matplotlib#1077
We forced the use of matplotlib version 3.0.2 because newer versions of matplotlib would raise a 'NotImplementedError' if a set_aspect('equal') method was called. There is no module which relies on said specific version anymore. We can therefore relax the requirement. More on the set_aspect() issue in matplotlib: matplotlib/matplotlib#1077 I also added 'tigl3' as an explicit dependency (again). I think all packages which are explicitly imported/used should be listed in ``environment.yml``, otherwise it becomes hard to track what is required and what is not. See also the note I made in the ``environment.yml`` file. Feel free to comment on this, if you disagree :)
The NotImplemented error was caused by the fact that set_aspect now causes an error in matplotlib (see matplotlib/matplotlib#1077 and matplotlib/matplotlib#13474). Fixed by making the figure itself square such that the 3D axis are square. Also change the fortan module's name from p2ptrans to fmodules which prevented from importing p2ptrans as a python module.
In order to get a future notification of |
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 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. |
@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? |
all what axis('equal') should do is this:
|
There is a PR that hopefully will be included in 3.6. #23409 |
aspect='equal'
argument is completely misused by axes3D.To verify:
The text was updated successfully, but these errors were encountered: