pyxem / orix

Analysing crystal orientations and symmetry in Python
https://orix.readthedocs.io
GNU General Public License v3.0
79 stars 45 forks source link

Allow setting padding and whether to show edges in StereographicPlot.restrict_to_sector() #424

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Description of the change

This PR adds the option to control the padding/margins in angles in the stereographic projection when restricting a StereographicPlot with restrict_to_sector(). The possibility to not show the sector edges as well as passing keyword arguments controlling the appearance of the sector (edge color, line width etc.) is also added.

An example drawing the Kikuchi bands of low-index {hkl} of Aluminium in the stereographic projection and then restricting to the m-3m fundamental sector is added to the examples.

Progress of the PR

Minimal example of the bug fix or new feature

This is the example added to the docs (can also be seen in the docs built from this PR):

import numpy as np

from orix.crystal_map import Phase
from orix.quaternion import symmetry
from orix.vector import Miller

# Symmetrically equivalent set of hkl
hkl1 = Miller(
    hkl=[[1, 1, 1], [2, 0, 0], [2, 2, 0], [3, 1, 1]],
    phase=Phase(point_group=symmetry.Oh),
)
print(hkl1)
hkl, idx = hkl1.symmetrise(unique=True, return_index=True)

# Width of Kikuchi bands (deviation from great circles)
theta = np.deg2rad([1.054, 1.218, 1.722, 2.019])
theta = theta[idx]

# Plot pair of near great circles
fig = hkl.draw_circle(opening_angle=np.pi / 2 + theta, return_figure=True)
hkl.draw_circle(opening_angle=np.pi / 2 - theta, figure=fig)

# Restrict to fundamental sector of m-3m
ax = fig.axes[0]
ax.restrict_to_sector(hkl.phase.point_group.fundamental_sector, edgecolor="r", lw=2)

# Get symmetrically equivalent set of zone axes <uvw> within fundamental
# sector and round to lowest possible integer
uvw = hkl.reshape(hkl.size, 1).cross(hkl.reshape(1, hkl.size)).flatten()
uvw = uvw.in_fundamental_sector()
uvw = uvw.unique(use_symmetry=True)
uvw = uvw.round()

# Plot zone axes
for uvw_i in uvw:
    uvw_idx = str(uvw_i.coordinates[0].astype(int)).replace(" ", "")
    ax.text(uvw_i, s=uvw_idx, va="bottom", bbox=dict(facecolor="w", pad=1, alpha=0.75))

_ = ax.set_title(r"Low-index $[uvw]$ in fundamental sector of $m\bar{3}m$", pad=10)

hkl_uvw

For reviewers

pc494 commented 1 year ago

Think float is legitimate, hence my choice in the merge. WIll wait for tests and then merge.