Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 587a528

Browse filesBrowse files
authored
Merge pull request #23747 from meeseeksmachine/auto-backport-of-pr-23721-on-v3.6.x
Backport PR #23721 on branch v3.6.x (3d plot view angle documentation)
2 parents d865462 + fd60d92 commit 587a528
Copy full SHA for 587a528

File tree

Expand file treeCollapse file tree

4 files changed

+101
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+101
-2
lines changed

‎doc/_static/mplot3d_view_angles.png

Copy file name to clipboard
24.4 KB
Loading

‎doc/api/toolkits/mplot3d.rst

Copy file name to clipboardExpand all lines: doc/api/toolkits/mplot3d.rst
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ more information.
2020

2121
The interactive backends also provide the ability to rotate and zoom the 3D
2222
scene. One can rotate the 3D scene by simply clicking-and-dragging the scene.
23-
Zooming is done by right-clicking the scene and dragging the mouse up and down
24-
(unlike 2D plots, the toolbar zoom button is not used).
23+
Panning is done by clicking the middle mouse button, and zooming is done by
24+
right-clicking the scene and dragging the mouse up and down. Unlike 2D plots,
25+
the toolbar pan and zoom buttons are not used.
2526

2627
.. toctree::
2728
:maxdepth: 2
2829

2930
mplot3d/faq.rst
31+
mplot3d/view_angles.rst
3032

3133
.. note::
3234
`.pyplot` cannot be used to add content to 3D plots, because its function
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. _toolkit_mplot3d-view-angles:
2+
3+
*******************
4+
mplot3d View Angles
5+
*******************
6+
7+
How to define the view angle
8+
============================
9+
10+
The position of the viewport "camera" in a 3D plot is defined by three angles:
11+
*elevation*, *azimuth*, and *roll*. From the resulting position, it always
12+
points towards the center of the plot box volume. The angle direction is a
13+
common convention, and is shared with
14+
`PyVista <https://docs.pyvista.org/api/core/camera.html>`_ and
15+
`MATLAB <https://www.mathworks.com/help/matlab/ref/view.html>`_
16+
(though MATLAB lacks a roll angle). Note that a positive roll angle rotates the
17+
viewing plane clockwise, so the 3d axes will appear to rotate
18+
counter-clockwise.
19+
20+
.. image:: /_static/mplot3d_view_angles.png
21+
:align: center
22+
:scale: 50
23+
24+
Rotating the plot using the mouse will control only the azimuth and elevation,
25+
but all three angles can be set programmatically::
26+
27+
import matplotlib.pyplot as plt
28+
ax = plt.figure().add_subplot(projection='3d')
29+
ax.view_init(elev=30, azim=45, roll=15)
30+
31+
32+
Primary view planes
33+
===================
34+
35+
To look directly at the primary view planes, the required elevation, azimuth,
36+
and roll angles are shown in the diagram of an "unfolded" plot below. These are
37+
further documented in the `.mplot3d.axes3d.Axes3D.view_init` API.
38+
39+
.. plot:: gallery/mplot3d/view_planes_3d.py
40+
:align: center

‎examples/mplot3d/view_planes_3d.py

Copy file name to clipboard
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
======================
3+
Primary 3D view planes
4+
======================
5+
6+
This example generates an "unfolded" 3D plot that shows each of the primary 3D
7+
view planes. The elevation, azimuth, and roll angles required for each view are
8+
labeled. You could print out this image and fold it into a box where each plane
9+
forms a side of the box.
10+
"""
11+
12+
import matplotlib.pyplot as plt
13+
14+
15+
def annotate_axes(ax, text, fontsize=18):
16+
ax.text(x=0.5, y=0.5, z=0.5, s=text,
17+
va="center", ha="center", fontsize=fontsize, color="black")
18+
19+
# (plane, (elev, azim, roll))
20+
views = [('XY', (90, -90, 0)),
21+
('XZ', (0, -90, 0)),
22+
('YZ', (0, 0, 0)),
23+
('-XY', (-90, 90, 0)),
24+
('-XZ', (0, 90, 0)),
25+
('-YZ', (0, 180, 0))]
26+
27+
layout = [['XY', '.', 'L', '.'],
28+
['XZ', 'YZ', '-XZ', '-YZ'],
29+
['.', '.', '-XY', '.']]
30+
fig, axd = plt.subplot_mosaic(layout, subplot_kw={'projection': '3d'},
31+
figsize=(12, 8.5))
32+
for plane, angles in views:
33+
axd[plane].set_xlabel('x')
34+
axd[plane].set_ylabel('y')
35+
axd[plane].set_zlabel('z')
36+
axd[plane].set_proj_type('ortho')
37+
axd[plane].view_init(elev=angles[0], azim=angles[1], roll=angles[2])
38+
axd[plane].set_box_aspect(None, zoom=1.25)
39+
40+
label = f'{plane}\n{angles}'
41+
annotate_axes(axd[plane], label, fontsize=14)
42+
43+
for plane in ('XY', '-XY'):
44+
axd[plane].set_zticklabels([])
45+
axd[plane].set_zlabel('')
46+
for plane in ('XZ', '-XZ'):
47+
axd[plane].set_yticklabels([])
48+
axd[plane].set_ylabel('')
49+
for plane in ('YZ', '-YZ'):
50+
axd[plane].set_xticklabels([])
51+
axd[plane].set_xlabel('')
52+
53+
label = 'mplot3d primary view planes\n' + 'ax.view_init(elev, azim, roll)'
54+
annotate_axes(axd['L'], label, fontsize=18)
55+
axd['L'].set_axis_off()
56+
57+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.