You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/api/toolkits/mplot3d/view_angles.rst
+116Lines changed: 116 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,3 +38,119 @@ further documented in the `.mplot3d.axes3d.Axes3D.view_init` API.
38
38
39
39
.. plot:: gallery/mplot3d/view_planes_3d.py
40
40
:align: center
41
+
42
+
43
+
Rotation with mouse
44
+
===================
45
+
46
+
3D plots can be reoriented by dragging the mouse.
47
+
There are various ways to accomplish this; the style of mouse rotation
48
+
can be specified by setting ``rcParams.axes3d.mouserotationstyle``, see
49
+
:doc:`/users/explain/customizing`.
50
+
51
+
Originally (with ``mouserotationstyle: azel``), the 2D mouse position
52
+
corresponded directly to azimuth and elevation; this is also how it is done
53
+
in `MATLAB <https://www.mathworks.com/help/matlab/ref/view.html>`_.
54
+
This approach works fine for polar plots, where the *z* axis is special;
55
+
however, it leads to a kind of 'gimbal lock' when looking down the *z* axis:
56
+
the plot reacts differently to mouse movement, dependent on the particular
57
+
orientation at hand. Also, 'roll' cannot be controlled.
58
+
59
+
As an alternative, there are various mouse rotation styles where the mouse
60
+
manipulates a 'trackball'. In its simplest form (``mouserotationstyle: trackball``),
61
+
the trackball rotates around an in-plane axis perpendicular to the mouse motion
62
+
(it is as if there is a plate laying on the trackball; the plate itself is fixed
63
+
in orientation, but you can drag the plate with the mouse, thus rotating the ball).
64
+
This is more natural to work with than the ``azel`` style; however,
65
+
the plot cannot be easily rotated around the viewing direction - one has to
66
+
drag the mouse in circles with a handedness opposite to the desired rotation.
67
+
68
+
A different variety of trackball rotates along the shortest arc on the virtual
69
+
sphere (``mouserotationstyle: arcball``); it is a variation on Ken Shoemake's
70
+
ARCBALL [Shoemake1992]_. Rotating around the viewing direction is straightforward
71
+
with it. Shoemake's original arcball is also available
72
+
(``mouserotationstyle: Shoemake``); it is free of hysteresis, i.e.,
73
+
returning mouse to the original position returns the figure to its original
74
+
orientation, the rotation is independent of the details of the path the mouse
75
+
took. However, Shoemake's arcball rotates at twice the angular rate of the
76
+
mouse movement (it is quite noticeable, especially when adjusting roll).
77
+
So it is a trade-off.
78
+
79
+
Shoemake's arcball has an abrupt edge; this is remedied in Holroyd's arcball
80
+
(``mouserotationstyle: Holroyd``).
81
+
82
+
Henriksen et al. [Henriksen2002]_ provide an overview.
83
+
84
+
In summary:
85
+
86
+
.. list-table::
87
+
:width: 100%
88
+
:widths: 30 20 20 20 35
89
+
90
+
* - Style
91
+
- traditional [1]_
92
+
- incl. roll [2]_
93
+
- uniform [3]_
94
+
- path independent [4]_
95
+
* - azel
96
+
- ✔️
97
+
- ❌
98
+
- ❌
99
+
- ✔️
100
+
* - trackball
101
+
- ❌
102
+
- ~
103
+
- ✔️
104
+
- ❌
105
+
* - arcball
106
+
- ❌
107
+
- ✔️
108
+
- ✔️
109
+
- ❌
110
+
* - Shoemake
111
+
- ❌
112
+
- ✔️
113
+
- ✔️
114
+
- ✔️
115
+
* - Holroyd
116
+
- ❌
117
+
- ✔️
118
+
- ✔️
119
+
- ✔️
120
+
121
+
122
+
.. [1] The way it was historically; this is also MATLAB's style
123
+
.. [2] Mouse controls roll too (not only azimuth and elevation)
124
+
.. [3] Figure reacts the same way to mouse movements, regardless of orientation (no difference between 'poles' and 'equator')
125
+
.. [4] Returning mouse to original position returns figure to original orientation (no hysteresis: rotation is independent of the details of the path the mouse took)
126
+
127
+
Try it out by adding a file ``matplotlibrc`` to folder ``matplotlib\galleries\examples\mplot3d``,
128
+
with contents::
129
+
130
+
axes3d.mouserotationstyle: arcball
131
+
132
+
(or any of the other styles), and run a suitable example, e.g.::
133
+
134
+
python surfaced3d.py
135
+
136
+
(If eternal compatibility with the horrors of the past is less of a consideration
137
+
for you, then it is likely that you would want to go with ``arcball``, ``Shoemake``,
138
+
or ``Holroyd``.)
139
+
140
+
The size of the trackball or arcball can be adjusted by setting
141
+
``rcParams.axes3d.trackballsize``, in units of the Axes bounding box;
142
+
i.e., to make the trackball span the whole bounding box, set it to 1.
143
+
A size of ca. 2/3 appears to work reasonably well.
144
+
145
+
----
146
+
147
+
.. [Shoemake1992] Ken Shoemake, "ARCBALL: A user interface for specifying
148
+
three-dimensional rotation using a mouse", in Proceedings of Graphics
149
+
Interface '92, 1992, pp. 151-156, https://doi.org/10.20380/GI1992.18
150
+
151
+
.. [Henriksen2002] Knud Henriksen, Jon Sporring, Kasper Hornbæk,
152
+
"Virtual Trackballs Revisited", in Proceedings of DSAGM'2002:
0 commit comments