Skip to content

Feature Request: non-square axes in axes3D #8593

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

Closed
huangziwei opened this issue May 8, 2017 · 2 comments
Closed

Feature Request: non-square axes in axes3D #8593

huangziwei opened this issue May 8, 2017 · 2 comments

Comments

@huangziwei
Copy link

Currently, we can get non-square axes in axes3D based on a simple hack from http://stackoverflow.com/a/10328142/2135095, by editing the get_proj function inside site-packages\mpl_toolkits\mplot3d\axes3d.py:

def get_proj(self):

    relev, razim = np.pi * self.elev/180, np.pi * self.azim/180

    try:
        self.localPbAspect = self.pbaspect
    except AttributeError:
        self.localPbAspect = [1,1,1]
    
    xmin, xmax = self.get_xlim3d() / self.localPbAspect[0]
    ymin, ymax = self.get_ylim3d() / self.localPbAspect[1]
    zmin, zmax = self.get_zlim3d() / self.localPbAspect[2]

then in the code we can set the axes manually:

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.pbaspect = [1,1,0.5]

it would be great if we can have some generic solution to achieve non-square axes.

@dstansby dstansby added this to the 2.2 (next next feature release) milestone Aug 29, 2017
@baloe
Copy link

baloe commented Jul 1, 2019

The hack above doesn't seem to work any more:

    xmin, xmax = self.get_xlim3d() / self.localPbAspect[0]
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'

So I modified get_proj in the following way:

        relev, razim = np.pi * self.elev/180, np.pi * self.azim/180

        try:
            self.localPbAspect = self.pbaspect
        except AttributeError:
            self.localPbAspect = [1,1,1]

        xmin, xmax = ( lim / self.localPbAspect[0] for lim in self.get_xlim3d() )
        ymin, ymax = ( lim / self.localPbAspect[1] for lim in self.get_ylim3d() )
        zmin, zmax = ( lim / self.localPbAspect[2] for lim in self.get_zlim3d() )

        # transform to uniform world coordinates 0-1.0,0-1.0,0-1.0
        worldM = proj3d.world_transformation(xmin, xmax,
                                             ymin, ymax,
                                             zmin, zmax)

This produces the desired output.

@story645 story645 removed this from the future releases milestone Oct 6, 2022
@pmolodo
Copy link

pmolodo commented Oct 22, 2024

For future searchers:

The way to set this now is via Axes3D.set_box_aspect([x, y, z])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants