Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve plotting of vector labels #443

Merged
merged 12 commits into from
May 2, 2023

Conversation

hakonanes
Copy link
Member

@hakonanes hakonanes commented Apr 9, 2023

Description of the change

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

  • Adding convenience function orix.plot.format_labels(v, brackets=("", ""), use_latex=True) accepting an array of vectors and returning an array of strings, one integer label per vector.
  • Adding an offset=None parameter in StereographicPlot.text() to control offset in stereographic coordinates (X, Y). When plotting with Vector3d.scatter(..., vector_labels=labels), this offset can be passed via text_kwargs={"offset": (0, 0.02)}".

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

  • The PR title is short, concise, and will make sense 1 year later.
  • New functions are imported in corresponding __init__.py.
  • New features, API changes, and deprecations are mentioned in the unreleased
    section in CHANGELOG.rst.
  • Contributor(s) are listed correctly in __credits__ in orix/__init__.py and in
    .zenodo.json.

@hakonanes hakonanes added the enhancement New feature or request label Apr 9, 2023
@hakonanes hakonanes added this to the v0.12.0 milestone Apr 9, 2023
@hakonanes hakonanes marked this pull request as draft April 20, 2023 09:31
@hakonanes hakonanes marked this pull request as ready for review April 22, 2023 13:47
@hakonanes hakonanes requested review from pc494 and harripj April 22, 2023 13:48
@pc494
Copy link
Member

pc494 commented Apr 23, 2023

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

@hakonanes
Copy link
Member Author

No problem, sounds good! Will fix the conflicts.

@hakonanes
Copy link
Member Author

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

@hakonanes hakonanes force-pushed the improve-vector-label-placement branch from b322fa2 to 262dfe2 Compare April 24, 2023 14:03
@hakonanes
Copy link
Member Author

Conflicts fixed, should be ready for review!

Copy link
Collaborator

@harripj harripj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay @hakonanes, this change looks great and will be helpful to users wanting to improve their figures. Would you mind if I make a very minor change to one of the notebooks just to add offset to one of the plots?

Copy link
Member

@pc494 pc494 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, I'll check @harripj got his change in and then mege.

@harripj
Copy link
Collaborator

harripj commented May 1, 2023

@pc494 feel free to merge!

@hakonanes
Copy link
Member Author

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

@hakonanes hakonanes force-pushed the improve-vector-label-placement branch from 2f9640a to ed126e1 Compare May 2, 2023 12:05
@hakonanes hakonanes merged commit f562362 into pyxem:develop May 2, 2023
@hakonanes hakonanes deleted the improve-vector-label-placement branch May 2, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants