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

Improve plotting of vector labels #443

Closed hakonanes closed 1 year ago

hakonanes commented 1 year ago

Description of the change

This PR improves plotting of vector labels in the stereographic projection by:

This makes labeling a pole figure much easier and nicer.

We can consider "extending" the vector_labels in Miller.scatter() by allowing it to be True, which then automatically creates the labels and adds them accordingly with the correct brackets (hkl/uvw). The danger is that this labeling assumes integer coordinates which might not be true for all vectors. If we add this, a warning should be raised in the case where rounding introduces an error in the coordinate labels above a certain threshold.

Progress of the PR

Minimal example of the bug fix or new feature

Create three sets of direct lattice vectors \<uvw> and plot them in the stereographic projection with labels and one color per family of directions

from orix import plot
from orix.crystal_map import Phase
from orix.vector import Miller

h = Miller(uvw=[[0, 0, 1], [1, 1, 1], [1, 1, 0]], phase=Phase(point_group="m-3m"))
h2, idx = h.symmetrise(unique=True, return_index=True)

h2.scatter(
    c=np.array([f"C{i}" for i in range(h.size)])[idx],
    vector_labels=plot.format_labels(h2.uvw, ("[", "]")),
    text_kwargs=dict(offset=(0, 0.02), bbox=dict(fc="w", ec="none", pad=0, alpha=0.75))
)

test

For reviewers

pc494 commented 1 year ago

Sorry @hakonanes, I should have reviewed this. Can I get it sometime next week once the conflicts (also my fault) have been resolved?

hakonanes commented 1 year ago

No problem, sounds good! Will fix the conflicts.

hakonanes commented 1 year ago

By 'no problem', I mean thanks for reviewing :)

hakonanes commented 1 year ago

Conflicts fixed, should be ready for review!

harripj commented 1 year ago

@pc494 feel free to merge!

hakonanes commented 1 year ago

Great, thank you guys for having a look! Will merge once the Python 3.7 build succeeds.