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

add third angle to view_init() #14453

Closed
baloe opened this issue Jun 5, 2019 · 9 comments · Fixed by #21426
Closed

add third angle to view_init() #14453

baloe opened this issue Jun 5, 2019 · 9 comments · Fixed by #21426

Comments

@baloe
Copy link

baloe commented Jun 5, 2019

Bug report

Bug summary

mpl_toolkits.mplot3d.axes3d.Axes3D.view_init
provides a means to set the elevation and the azimuth, but the z-axis is always aligned with the vertical camera axis.
A third angle would be required to permit any view.

The issue was reported on stackoverflow 3.5 years ago.

Code for reproduction

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = Axes3D(fig)

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()

Actual outcome

Figure_1

Now, however hard you try to rotate the plot interactively or what angles you set in ax.view_init(), you will never be able to get the z-axis in a horizontalish position that is required to produce the plot below:

Expected outcome

By rotating interactively or via ax.view_init() one should be able to obtain this view below. Unfortunately, this is not possible.
Figure_2

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 3.1.0, py37h5429711_0
  • Matplotlib backend: Qt5Agg
  • Python version: 3.7.3 (conda)
@SReich-EMI
Copy link

my searching of how this could work ends here. I would kindly ask the community to implement this third angle to complete the 3D plotting in this case.

@WeatherGod
Copy link
Member

WeatherGod commented Mar 10, 2021 via email

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Oct 21, 2021

This is something I've been frustrated with pretty much every single time I need to plot something in 3D, and I'm going to take a stab at it this weekend and see how far I can get.

The missing piece is that azimuth, elevation, and radius uniquely define a viewpoint in 3D space, but you need an additional angle defining the rotation about the radius vector in order to fully capture the entire space of view orientations. If we add this 3rd angle with a default value of 0 deg, it should not break any old code.

As to naming this additional angle, I think roll is the obvious choice. It aligns with both the aerospace pith/yaw/roll convention, as well as the camera angle pan/tilt/roll convention. On the other hand I have seen tilt, twist, lean, and bank used for this angle, so if someone has a strong opinion or a source for the canonical term used in computer graphics I'm open to that. We will be jumping ahead of matlab features a bit, so if they decide to add this in the future and choose a different name there is the risk of divergence.

Really this should be done using quaternions - Euler angles are pretty much always bad. But since quaternions aren't natively in numpy we probably don't want to introduce those as a dependency just to avoid gimbal lock at the two poles.

@scottshambaugh
Copy link
Contributor

This looks like a relevant PR to keep in mind when reworking this: #10762

@timhoffm
Copy link
Member

There are two aspects to consider:

  • With the restricted two angles, the final view direction does not depend on the execution order of the two rotations.
    With three angles, you have to find a reasonable execution order and document that.
  • When interactively navigating in the view window we currently map the two screeen directions horizontal/vertical to azimuth/elevation. AFAICS there is no simple way of controlling the third dimension interactively (though one might look at 3d programs how they solve this)

@scottshambaugh
Copy link
Contributor

scottshambaugh commented Oct 22, 2021

Finished my PR, it's ready for review.

@baloe
Copy link
Author

baloe commented Dec 3, 2021

This is brilliant, thank you so much @scottshambaugh !

@baloe
Copy link
Author

baloe commented Dec 3, 2021

I updated my answer in the SO thread: https://stackoverflow.com/a/56457693/7042795

@tacaswell tacaswell added this to the v3.6.0 milestone Dec 3, 2021
@SReich-EMI
Copy link

Thanks a lot for your work! I will surely test it in the next days!

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.

8 participants