Skip to content
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

3d plots with aspect='equal' #1077

Closed
akhmerov opened this issue Aug 12, 2012 · 23 comments

Comments

Projects
None yet
@akhmerov
Copy link
Contributor

commented Aug 12, 2012

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.
@WeatherGod

This comment has been minimized.

Copy link
Member

commented 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

This comment has been minimized.

Copy link
Contributor Author

commented 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

This comment has been minimized.

Copy link

commented Jan 23, 2013

I would also be interested by this feature.
By the way, did you found a way to tackle the problem?

@astrofrog

This comment has been minimized.

Copy link
Contributor

commented Feb 24, 2013

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)

@tehingo

This comment has been minimized.

Copy link

commented 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

This comment has been minimized.

Copy link
Contributor Author

commented 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.

@tacaswell tacaswell added this to the v1.4.x milestone Aug 18, 2014

@tacaswell tacaswell modified the milestones: v1.4.x, unassigned Aug 18, 2014

@Hanlin-Dong

This comment has been minimized.

Copy link

commented 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

This comment has been minimized.

Copy link
Contributor Author

commented 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

This comment has been minimized.

Copy link

commented 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

This comment has been minimized.

Copy link

commented May 6, 2018

screen shot 2018-05-05 at 8 30 52 pm

I just got this plot after calling ax.set_aspect('equal'). Definitely not equal based on the ticks!

@timhoffm

This comment has been minimized.

Copy link
Member

commented May 6, 2018

Related and possibly a first step for fixing this: #8896

@samuela

This comment has been minimized.

Copy link

commented May 6, 2018

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.

@samuela

This comment has been minimized.

Copy link

commented May 7, 2018

cc @nfoti

@SicariusNoctis

This comment has been minimized.

Copy link

commented Jun 3, 2018

Just thought I'd chime in with my own SO post.

As shown below, a square does not look like a square:

@dstansby

This comment has been minimized.

Copy link
Contributor

commented Jul 26, 2018

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 aspect='equal'?

@timhoffm

This comment has been minimized.

Copy link
Member

commented Jul 26, 2018

👍 a warning would be reasonable and sufficient.

@jklymak jklymak modified the milestones: unassigned, v3.1 Jul 26, 2018

@samuela

This comment has been minimized.

Copy link

commented Jul 26, 2018

@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.

@droundy

This comment has been minimized.

Copy link

commented Feb 20, 2019

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

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2019

Closing due to #13474 and the fact that the non-optimal behaviour is discussed in previous issues and PRs references above...

@jklymak jklymak closed this Mar 3, 2019

@akhmerov

This comment has been minimized.

Copy link
Contributor Author

commented 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

This comment has been minimized.

Copy link

commented 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

This comment has been minimized.

Copy link
Contributor

commented 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..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.