Skip to content

Feature Request: non-square axes in axes3D #8593

Closed

Description

@huangziwei

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.

Activity

  1. added this to the milestone on Aug 29, 2017
  2. baloe commented on Jul 1, 2019

    @baloe

    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.

  3. removed this from the future releases milestone on Oct 6, 2022
  4. pmolodo commented on Oct 22, 2024

    @pmolodo

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions