Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24c3a53

Browse files
committed
Make 3D rotation snap angle configurable via rcParams
1 parent bae4094 commit 24c3a53

5 files changed

Lines changed: 30 additions & 6 deletions

File tree

doc/api/toolkits/mplot3d.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,10 @@ the toolbar pan and zoom buttons are not used.
121121
proj3d.proj_transform
122122
proj3d.proj_transform_clip
123123
proj3d.world_transformation
124+
125+
Rotation snapping
126+
~~~~~~~~~~~~~~~~~
127+
128+
When rotating a 3D Axes while holding the Control key, the rotation
129+
angle is snapped to increments defined by the rcParam
130+
:rc:`axes3d._snap_rotation` (default: 5 degrees).
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
3D rotation snapping via Control key
2+
-------------------------------------
3+
4+
Holding the Control key while rotating a 3D Axes snaps the rotation
5+
angle to configurable increments. The snap angle is controlled via
6+
the rcParam :rc:`axes3d._snap_rotation`, which defaults to 5 degrees.

lib/matplotlib/rcsetup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ def _convert_validator_spec(key, conv):
11811181
"axes3d.mouserotationstyle": ["azel", "trackball", "sphere", "arcball"],
11821182
"axes3d.trackballsize": validate_float,
11831183
"axes3d.trackballborder": validate_float,
1184+
"axes3d.snap_rotation": validate_float,
11841185

11851186
# scatter props
11861187
"scatter.marker": _validate_marker,
@@ -2143,6 +2144,12 @@ class _Param:
21432144
description="trackball border width, in units of the Axes bbox (only for "
21442145
"'sphere' and 'arcball' style)"
21452146
),
2147+
_Param(
2148+
"axes3d.snap_rotation",
2149+
default=0.0,
2150+
validator=validate_float,
2151+
description="Snap angle (in degrees) for 3D rotation when holding Control."
2152+
),
21462153
_Param(
21472154
"xaxis.labellocation",
21482155
default="center",

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,12 +1612,14 @@ def _on_move(self, event):
16121612

16131613
q = dq * q
16141614
elev, azim, roll = np.rad2deg(q.as_cardan_angles())
1615-
if getattr(self, "_snap_rotation", False):
1616-
step = 5
1617-
elev = float(step * round(elev / step))
1618-
azim = float(step * round(azim / step))
1619-
roll = float(step * round(roll / step))
1620-
1615+
if (
1616+
self._snap_rotation
1617+
and mpl.rcParams["axes3d.snap_rotation"] > 0
1618+
):
1619+
step = mpl.rcParams["axes3d.snap_rotation"]
1620+
elev = step * round(elev / step)
1621+
azim = step * round(azim / step)
1622+
roll = step * round(roll / step)
16211623
# update view
16221624
vertical_axis = self._axis_names[self._vertical_axis]
16231625
self.view_init(

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,6 +2819,8 @@ def test_ctrl_rotation_snaps_to_5deg(monkeypatch):
28192819

28202820
ax._snap_rotation = True
28212821

2822+
monkeypatch.setitem(plt.rcParams, "axes3d.snap_rotation", 5)
2823+
28222824
monkeypatch.setitem(plt.rcParams, "axes3d.mouserotationstyle", "azel")
28232825

28242826
captured = {}

0 commit comments

Comments
 (0)