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

[Bug]: set_aspect incompatible with view_init #28052

Open
simbamford opened this issue Apr 9, 2024 · 2 comments · May be fixed by #28041
Open

[Bug]: set_aspect incompatible with view_init #28052

simbamford opened this issue Apr 9, 2024 · 2 comments · May be fixed by #28041

Comments

@simbamford
Copy link

Bug summary

ax.set_aspect('equal') doesn't work properly on axes where the view has been manipulated, i.e. ax.view_init(vertical_axis='y').
It sets the aspect ratio as if the axes were still oriented in the standard way.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as a3

plt.close('all')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(vertical_axis='y')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_xlabel('Z')
ax.axes.set_xlim3d(left=-1, right=3.5) 
ax.axes.set_ylim3d(bottom=0, top=10) 
ax.axes.set_zlim3d(bottom=-0.5, top=3.5) 
ax.set_aspect('equal')
    
def a(elemList):
    return np.array(elemList)

def drawTriangle(centre, size=1, color='y'):
    # A neuron is a triangle
    left = centre + a([- size / 2, - size / 2, 0])
    right = centre + a([size / 2, - size / 2, 0])
    top = centre + a([0, size / 2, 0])
    coords = a([left, top, right])
    tri = a3.art3d.Poly3DCollection([coords])
    tri.set_color(color)
    tri.set_edgecolor('k')
    ax.add_collection3d(tri)

for col in range(3):
    drawTriangle(a([col, 10, 0]))

Actual outcome

image

Expected outcome

You would want the vertical 'y' axis to be stretched to 10 units, instead the horizontal 'z' axis has been stretched.

Additional information

No response

Operating system

No response

Matplotlib Version

3.7.2

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

@Illviljan Illviljan linked a pull request Apr 14, 2024 that will close this issue
3 tasks
@Illviljan
Copy link
Contributor

With #28041 I get:
image

@simbamford
Copy link
Author

Yes - that's much better, thanks :)

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

Successfully merging a pull request may close this issue.

3 participants