|
1 | 1 | r""" |
2 | | -======================== |
3 | | -Plot symmetry operations |
4 | | -======================== |
| 2 | +======================================== |
| 3 | +Plot Paths Through Non-Euclidean Spaces |
| 4 | +======================================== |
5 | 5 |
|
6 | | -This example shows how to use the `from_path_ends` functions from |
7 | | -:class:`~orix.vector.Vector3d`, :class:`~orix.quaternions.Rotation`, and |
8 | | -:class:`~orix.quaternions.Orientation` to draw paths through thier |
9 | | -respective non-Euclidean spaces. |
| 6 | +This example shows three variations on how 'from_path_ends' can be |
| 7 | +used to plot paths between points in rotational and vector spaces. |
| 8 | +
|
| 9 | +This functionality is available in :class:`~orix.vector.Vector3d`, |
| 10 | +:class:`~orix.quaternions.Rotation`, |
| 11 | +:class:`~orix.quaternions.Orientation`, |
| 12 | +and :class:`~orix.quaternions.Misorientation`. |
10 | 13 | """ |
11 | 14 |
|
12 | 15 | import matplotlib.pyplot as plt |
| 16 | +from matplotlib import cm |
13 | 17 | import numpy as np |
14 | 18 |
|
15 | | -from orix.quaternion import Orientation, Rotation |
| 19 | +from orix.quaternion import Misorientation, Orientation, Rotation |
16 | 20 | from orix.quaternion.symmetry import D3, Oh |
17 | 21 | from orix.vector import Vector3d |
18 | 22 |
|
19 | | -fig = plt.figure() |
| 23 | +fig = plt.figure(figsize=(4, 8)) |
20 | 24 |
|
21 | | -# plot a path in homochoric space with no symmetry |
22 | | -rot_path = Rotation( |
| 25 | +# ========= # |
| 26 | +# Example 1: Plotting a path of rotations with no symmetry in homochoric space |
| 27 | +# ========= # |
| 28 | +rots_along_path = Rotation( |
23 | 29 | data=np.array( |
24 | 30 | [ |
25 | 31 | [1, 0, 0, 0], |
26 | | - [1, 1, 0, 0], |
27 | | - [1, 0, 1, 0], |
28 | 32 | [1, 0, 0, 1], |
29 | | - [1, 0, -1, 0], |
30 | | - [1, 0, 0, -1], |
31 | | - [1, 0, 0, -1], |
| 33 | + [1, 1, 1, 1], |
32 | 34 | ] |
33 | 35 | ) |
34 | 36 | ) |
35 | | -rotation_path = Rotation.from_path_ends(rot_path, closed=True) |
36 | | -# cast the rotation to a symmetry-less orientation for plotting purposes |
37 | | -Orientation(rotation_path).scatter( |
38 | | - figure=fig, position=[2, 2, 1], marker=">", c=np.arange(700) |
39 | | -) |
| 37 | +n_steps = 20 |
| 38 | +rotation_path = Rotation.from_path_ends(rots_along_path, steps=n_steps) |
| 39 | +# create an Orientation loop using this path with no symmetry elements |
| 40 | +ori_path = Orientation(rotation_path) |
| 41 | +# plot the path in homochoric space |
| 42 | +segment_colors = cm.inferno(np.linspace(0, 1, n_steps)) |
40 | 43 |
|
41 | | -# plot a path in rodrigues space with m-3m (cubic) symmetry. |
42 | | -m3m_path = Orientation( |
| 44 | +path_colors = np.vstack([segment_colors for x in range(rots_along_path.size - 1)]) |
| 45 | +ori_path.scatter(figure=fig, position=[3, 1, 1], marker=">", c=path_colors) |
| 46 | +fig.axes[0].set_title(r"$90^\circ$ rotation around X, then Y") |
| 47 | + |
| 48 | +# ========= # |
| 49 | +# Example 2: Plotting the rotation of several orientations in m3m Rodrigues |
| 50 | +# space around the z axis. |
| 51 | +# ========= # |
| 52 | +oris = Orientation( |
43 | 53 | data=np.array( |
44 | 54 | [ |
45 | | - [1, 0, 0, 0], |
46 | | - [2, 1, 0, 0], |
47 | | - [3, 0, 1, 0], |
48 | | - [4, 0, 0, 1], |
49 | | - [5, 0, -1, 0], |
50 | | - [6, 0, 0, -1], |
51 | | - [7, 0, 0, -1], |
52 | | - [8, 1, 0, 0], |
53 | | - [9, 0, 1, 0], |
54 | | - [10, 0, 0, 1], |
55 | | - [11, 0, -1, 0], |
56 | | - [12, 0, 0, -1], |
57 | | - [13, 0, 0, -1], |
| 55 | + [0.69, 0.24, 0.68, 0.01], |
| 56 | + [0.26, 0.59, 0.32, 0.7], |
| 57 | + [0.07, 0.17, 0.93, 0.31], |
| 58 | + [0.6, 0.03, 0.61, 0.52], |
| 59 | + [0.51, 0.38, 0.34, 0.69], |
| 60 | + [0.31, 0.86, 0.22, 0.35], |
| 61 | + [0.68, 0.67, 0.06, 0.31], |
| 62 | + [0.01, 0.12, 0.05, 0.99], |
| 63 | + [0.39, 0.45, 0.34, 0.72], |
| 64 | + [0.65, 0.59, 0.46, 0.15], |
58 | 65 | ] |
59 | 66 | ), |
60 | 67 | symmetry=Oh, |
| 68 | +).reduce() |
| 69 | +# define a 20 degree rotation around the z axis |
| 70 | +shift = Orientation.from_axes_angles([0, 0, 1], np.pi / 9) |
| 71 | +segment_colors = cm.inferno(np.linspace(0, 1, 10)) |
| 72 | + |
| 73 | +ori_paths = [] |
| 74 | +for ori in oris: |
| 75 | + shifted = (shift * ori).reduce() |
| 76 | + to_from = Orientation.stack([ori, shifted]).flatten() |
| 77 | + ori_paths.append(Orientation.from_path_ends(to_from, steps=10)) |
| 78 | +# plot a path in roddrigues space with m-3m (cubic) symmetry. |
| 79 | +ori_path = Orientation.stack(ori_paths).flatten() |
| 80 | +ori_path.symmetry = Oh |
| 81 | +ori_path.scatter( |
| 82 | + figure=fig, |
| 83 | + position=[3, 1, 2], |
| 84 | + marker=">", |
| 85 | + c=np.tile(segment_colors, [10, 1]), |
| 86 | + projection="rodrigues", |
61 | 87 | ) |
62 | | -orientation_path = Orientation.from_path_ends(m3m_path.reduce(), closed=True).reduce() |
63 | | -orientation_path.scatter(figure=fig, position=[2, 2, 2], marker=">", c=np.arange(1300)) |
| 88 | +fig.axes[1].set_title(r"$20^{\circ}$ rotations around X-axis in m3m") |
64 | 89 |
|
65 | | -# plot a second path in rodrigues space with symmetry, but while also crossing a |
66 | | -# symmetry boundary |
67 | | -fiber_start = Rotation.identity(1) |
68 | | -fiber_middle = Rotation.from_axes_angles([1, 2, 3], np.pi) |
69 | | -fiber_end = Rotation.from_axes_angles([1, 2, 3], 2 * np.pi) |
70 | | -fiber_points = Orientation.stack([fiber_start, fiber_middle, fiber_end]) |
71 | | -fiber_points.symmetry = Oh |
72 | | -fiber_path = Orientation.from_path_ends(fiber_points, closed=False).reduce() |
73 | | -fiber_path.scatter(figure=fig, position=[2, 2, 3], marker=">", c=np.arange(200)) |
| 90 | +# ========= # |
| 91 | +# Example 3: creating a customized Wulf Plotting the rotation of several orientations in m3m Rodrigues |
| 92 | +# space around the z axis. |
| 93 | +# ========= # |
74 | 94 |
|
75 | 95 |
|
76 | 96 | # plot vectors |
77 | | -ax4 = plt.subplot(2, 2, 4, projection="stereographic") |
78 | | -vector_points = Vector3d( |
79 | | - np.array([[-1, 0, 0], [0, 1, 0.1], [1, 0, 0.2], [0, -1, 0.3], [-1, 0, 0.4]]) |
80 | | -) |
| 97 | +ax_upper = plt.subplot(3, 1, 3, projection="stereographic", hemisphere="upper") |
| 98 | +r90x = Rotation.from_axes_angles([1, -1, -1], [0, 60], degrees=True) |
| 99 | +x_axis_points = r90x * Vector3d.xvector() |
| 100 | +y_axis_points = r90x * Vector3d.yvector() |
| 101 | +z_axis_points = r90x * Vector3d.zvector() |
| 102 | + |
| 103 | +x_axis_path = Vector3d.from_path_ends(x_axis_points.unique()) |
| 104 | +y_axis_path = Vector3d.from_path_ends(y_axis_points.unique()) |
| 105 | +z_axis_path = Vector3d.from_path_ends(z_axis_points.unique()) |
| 106 | +cx = cm.Reds(np.linspace(0.1, 1, x_axis_path.size)) |
| 107 | +cy = cm.Greens(np.linspace(0.1, 1, y_axis_path.size)) |
| 108 | +cz = cm.Blues(np.linspace(0.1, 1, z_axis_path.size)) |
| 109 | + |
| 110 | +spx = ax_upper.scatter(x_axis_path, figure=fig, marker=">", c=cx, label="X") |
| 111 | +spy = ax_upper.scatter(y_axis_path, figure=fig, marker=">", c=cy, label="Y") |
| 112 | +spz = ax_upper.scatter(z_axis_path, figure=fig, marker=">", c=cz, label="Z") |
| 113 | +ax_upper.legend(loc="lower center", ncols=3) |
81 | 114 |
|
82 | | -vector_path = Vector3d.from_path_ends(vector_points, steps=200) |
83 | | -ax4.scatter(vector_path, figure=fig, marker=">", c=np.arange(vector_path.size)) |
| 115 | +plt.tight_layout() |
0 commit comments