FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[ENH]: Provide `axis('equal')` for `Axes3D`. · Issue #22570 · matplotlib/matplotlib · GitHub

Repository navigation

[ENH]: Provide axis('equal') for Axes3D. #22570

Closed

Description

Bug summary

In the example below, I wish to observe a unitary 3D cube in its diagonal axis (1, 1, 1).
azimut and elevation angle should be both 45°, normally.
Why do I need to set elevation = 28° ????
Thanks,
Patrick

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 3, figsize=(15, 5),
                       subplot_kw=dict(projection="3d",
                                       proj_type='ortho'))

ax[0].voxels(np.ones((1, 1, 1)), facecolors=[0, 0, 0, 0], edgecolors='k')
ax[0].quiver(0, 0, 0, 1, 1, 1, color='r', linewidth=5)

ax[1].set_title("azim=45°, elev=45°")
ax[1].voxels(np.ones((1, 1, 1)), facecolors=[0, 0, 0, 0], edgecolors='k')
ax[1].view_init(azim=45, elev=45)
ax[1].quiver(0, 0, 0, 1, 1, 1, color='r', linewidth=5)

ax[2].set_title("azim=45°, elev=28°")
ax[2].voxels(np.ones((1, 1, 1)), facecolors=[0, 0, 0, 0], edgecolors='k')
ax[2].view_init(azim=45, elev=28)
ax[2].quiver(0, 0, 0, 1, 1, 1, color='r', linewidth=5)

plt.show()

Actual outcome

Expected outcome

view_init(azim=45, elev=45) and not view_init(azim=45, elev=28) to have the expected 3D representation

Additional information

No response

Operating system

Windows

Matplotlib Version

3.4.2

Matplotlib Backend

No response

Python version

Python 3.7.7

Jupyter version

No response

Installation

pip

Activity

  1. oscargus commented on Feb 28, 2022

    Member

    Ideally, it should be possible to do ax[1].axis('equal') to obtain what you are looking for (see https://matplotlib.org/stable/gallery/subplots_axes_and_figures/axis_equal_demo.html). However, Axes3D does not (yet) support that:

    Traceback (most recent call last):
    
      Input In [18] in <module>
        ax[1].axis('equal')
    
      File /local/data1/miniconda3/lib/python3.8/site-packages/matplotlib/axes/_base.py:2047 in axis
        self.set_aspect('equal', adjustable='datalim')
    
      File /local/data1/miniconda3/lib/python3.8/site-packages/mpl_toolkits/mplot3d/axes3d.py:311 in set_aspect
        raise NotImplementedError(
    
    NotImplementedError: Axes3D currently only supports the aspect argument 'auto'. You passed in 'equal'.
    

    So, basically, there is a different scaling for the z-axis compared to the x- and y-axes. You can see that from the grid blocks being rectangles (rather than squares, as for the bottom surface).

  2. changed the title [-][Bug]: elevation angle not correct with view_init() ?[/-] [+][ENH]: Provide `axis('equal')` for `Axes3D`.[/+] on Feb 28, 2022
  3. oscargus commented on Feb 28, 2022

    Member

    You can get a bit closer by using: ax[1].set_box_aspect((4, 4, 4)), but it is still not exact. (Of course, you can probably find a better value for the last number, but that is about as bad as 28 degrees...) Now it at least looks like a cube.

  4. patquem commented on Feb 28, 2022

    ContributorAuthor

    Hi @oscargus,
    Thanks for your reply.
    using ax[1].set_box_aspect((1, 1, 1)), the elevation angle is now 35°.
    That is the correct elevation angle (atan(1/sqrt(2) ~35°) and not 45° as I have previously written.
    Thanks.

  5. jondo commented on Aug 2, 2022

    B.t.w., this is a successor of #1077.

  6. added this to the v3.6.0 milestone on Aug 3, 2022
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL