-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
3d plot view angle documentation #23721
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
.. _toolkit_mplot3d-view-angles: | ||
|
||
******************* | ||
mplot3d View Angles | ||
******************* | ||
|
||
How to define the view angle | ||
============================ | ||
|
||
The position of the viewport "camera" in a 3D plot is defined by three angles: | ||
*elevation*, *azimuth*, and *roll*. From the resulting position, it always | ||
points towards the center of the plot box volume. The angle direction is a | ||
common convention, and is shared with | ||
`PyVista <https://docs.pyvista.org/api/core/camera.html>`_ and | ||
`MATLAB <https://www.mathworks.com/help/matlab/ref/view.html>`_ | ||
(though MATLAB lacks a roll angle). Note that a positive roll angle rotates the | ||
viewing plane clockwise, so the 3d axes will appear to rotate | ||
counter-clockwise. | ||
|
||
.. image:: /_static/mplot3d_view_angles.png | ||
:align: center | ||
:scale: 50 | ||
|
||
Rotating the plot using the mouse will control only the azimuth and elevation, | ||
but all three angles can be set programmatically:: | ||
|
||
import matplotlib.pyplot as plt | ||
ax = plt.figure().add_subplot(projection='3d') | ||
ax.view_init(elev=30, azim=45, roll=15) | ||
|
||
|
||
Primary view planes | ||
=================== | ||
|
||
To look directly at the primary view planes, the required elevation, azimuth, | ||
and roll angles are shown in the diagram of an "unfolded" plot below. These are | ||
further documented in the `.mplot3d.axes3d.Axes3D.view_init` API. | ||
|
||
.. plot:: gallery/mplot3d/view_planes_3d.py | ||
:align: center |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
====================== | ||
Primary 3D view planes | ||
====================== | ||
|
||
This example generates an "unfolded" 3D plot that shows each of the primary 3D | ||
view planes. The elevation, azimuth, and roll angles required for each view are | ||
labeled. You could print out this image and fold it into a box where each plane | ||
forms a side of the box. | ||
""" | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
|
||
def annotate_axes(ax, text, fontsize=18): | ||
ax.text(x=0.5, y=0.5, z=0.5, s=text, | ||
va="center", ha="center", fontsize=fontsize, color="black") | ||
|
||
# (plane, (elev, azim, roll)) | ||
views = [('XY', (90, -90, 0)), | ||
('XZ', (0, -90, 0)), | ||
('YZ', (0, 0, 0)), | ||
('-XY', (-90, 90, 0)), | ||
('-XZ', (0, 90, 0)), | ||
('-YZ', (0, 180, 0))] | ||
|
||
layout = [['XY', '.', 'L', '.'], | ||
['XZ', 'YZ', '-XZ', '-YZ'], | ||
['.', '.', '-XY', '.']] | ||
fig, axd = plt.subplot_mosaic(layout, subplot_kw={'projection': '3d'}, | ||
figsize=(12, 8.5)) | ||
for plane, angles in views: | ||
axd[plane].set_xlabel('x') | ||
axd[plane].set_ylabel('y') | ||
axd[plane].set_zlabel('z') | ||
axd[plane].set_proj_type('ortho') | ||
axd[plane].view_init(elev=angles[0], azim=angles[1], roll=angles[2]) | ||
axd[plane].set_box_aspect(None, zoom=1.25) | ||
|
||
label = f'{plane}\n{angles}' | ||
annotate_axes(axd[plane], label, fontsize=14) | ||
|
||
for plane in ('XY', '-XY'): | ||
axd[plane].set_zticklabels([]) | ||
axd[plane].set_zlabel('') | ||
for plane in ('XZ', '-XZ'): | ||
axd[plane].set_yticklabels([]) | ||
axd[plane].set_ylabel('') | ||
for plane in ('YZ', '-YZ'): | ||
axd[plane].set_xticklabels([]) | ||
axd[plane].set_xlabel('') | ||
|
||
label = 'mplot3d primary view planes\n' + 'ax.view_init(elev, azim, roll)' | ||
annotate_axes(axd['L'], label, fontsize=18) | ||
axd['L'].set_axis_off() | ||
|
||
plt.show() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be a good use for
axs[plane].axis('equal')
? 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cutout should work for any aspect box :). But right now that command would only change the data limits! Need #23552 to merge in to change the box.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's to this later then. Since we've already released 3.6 RC1, #23552 can't go into 3.6 anymore.