Skip to content

Commit 4b27b9f

Browse files
committed
Merge branch 'adopt-reduce-and-other-updates-from-pyxem#442' of https://github.com/argerlt/orix into adopt-reduce-and-other-updates-from-pyxem#442
2 parents 1aeb7a9 + e5c307f commit 4b27b9f

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
r"""
2+
========================================
3+
Plot Paths Through Non-Euclidean Spaces
4+
========================================
5+
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`.
13+
"""
14+
15+
import matplotlib.pyplot as plt
16+
from matplotlib import cm
17+
import numpy as np
18+
19+
from orix.quaternion import Misorientation, Orientation, Rotation
20+
from orix.quaternion.symmetry import D3, Oh
21+
from orix.vector import Vector3d
22+
23+
fig = plt.figure(figsize=(4, 8))
24+
25+
# ========= #
26+
# Example 1: Plotting a path of rotations with no symmetry in homochoric space
27+
# ========= #
28+
rots_along_path = Rotation(
29+
data=np.array(
30+
[
31+
[1, 0, 0, 0],
32+
[1, 0, 0, 1],
33+
[1, 1, 1, 1],
34+
]
35+
)
36+
)
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))
43+
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(
53+
data=np.array(
54+
[
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],
65+
]
66+
),
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",
87+
)
88+
fig.axes[1].set_title(r"$20^{\circ}$ rotations around X-axis in m3m")
89+
90+
# ========= #
91+
# Example 3: creating a customized Wulf Plotting the rotation of several orientations in m3m Rodrigues
92+
# space around the z axis.
93+
# ========= #
94+
95+
96+
# plot vectors
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)
114+
115+
plt.tight_layout()

0 commit comments

Comments
 (0)