Skip to content

3d plots of unit cells#648

Open
argerlt wants to merge 3 commits into
pyxem:developfrom
argerlt:3d-plots-of-unit-cells
Open

3d plots of unit cells#648
argerlt wants to merge 3 commits into
pyxem:developfrom
argerlt:3d-plots-of-unit-cells

Conversation

@argerlt
Copy link
Copy Markdown
Collaborator

@argerlt argerlt commented Apr 11, 2026

Breaking out this part of #563 into it's own PR. It can be pushed before or after #647.

Description of the change

Adds the unit cell plotting tool originally mentioned in #563 before that spiraled out into a bigger topic. I can add examples now if we want, but similar to #647, it might make more sense to add examples as part of #563 while replacing the related tutorial notebooks.

Progress of the PR

Minimal example of the bug fix or new feature

import orix.crystal_map as ocm
import matplotlib.pyplot as plt
import diffpy.structure as dst

# define two different phases slightly different ways.

# Alumina first
Al2O3_atoms = [
    dst.Atom("Al", [1 / 3, 2 / 3, 0.815]),
    dst.Atom("O", [0.361, 1 / 3, 0.583]),
]
Al2O3_lattice = dst.Lattice(0.481, 0.481, 1.391, 90, 90, 120)
Al2O3_structure = dst.Structure(atoms=Al2O3_atoms, lattice=Al2O3_lattice)
Al2O3_phase = ocm.Phase(
    name="Alumina",
    space_group=167,
    structure=Al2O3_structure,
    color="red",
).expand_asymmetric_unit()

# Then alpha iron
Fe_atoms = [
    dst.Atom("Fe", [0, 0, 0]),
    dst.Atom("Fe", [1, 0, 0]),
    dst.Atom("Fe", [0, 1, 0]),
    dst.Atom("Fe", [0, 0, 1]),
    dst.Atom("Fe", [0, 1, 1]),
    dst.Atom("Fe", [1, 0, 1]),
    dst.Atom("Fe", [1, 1, 0]),
    dst.Atom("Fe", [1, 1, 1]),
    dst.Atom("Fe", [1 / 2, 1 / 2, 1 / 2]),
]
Fe_lattice = dst.Lattice(1, 1, 1, 90, 90, 90)
Fe_structure = dst.Structure(atoms=Fe_atoms, lattice=Fe_lattice)
Fe_phase = ocm.Phase(point_group="m3m", structure=Fe_structure)

# For both, make a standard plot, as well as a nicer one.
for p in [Al2O3_phase, Fe_phase]:
    fig1 = p.plot_unit_cell(figsize=[5, 4], return_figure=True)
    p.plot_unit_cell(show_xyz=True, show_atoms=True, show_uvw_labels=True)
image

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.

@argerlt
Copy link
Copy Markdown
Collaborator Author

argerlt commented Apr 11, 2026

pre-commit.ci autofix

@CSSFrancis
Copy link
Copy Markdown
Member

I've been playing around with creating a new plotting library backend for hyperspy and other related EM packages. I wonder if it might be useful here eventually.

https://cssfrancis.github.io/anyplotlib/dev/auto_examples/plot_3d.html

I might need to add additional functionality but I don't think it should be too difficult to support something like this.

@argerlt
Copy link
Copy Markdown
Collaborator Author

argerlt commented Apr 20, 2026

I've been playing around with creating a new plotting library backend for hyperspy and other related EM packages. I wonder if it might be useful here eventually.

https://cssfrancis.github.io/anyplotlib/dev/auto_examples/plot_3d.html

I think what I'm doing here is too basic for anyplotlib, and I also want to keep dependencies as low as possible so I can use this feature later on as an overlay for crystal map plots.

That said, keeping this as a mental note for when I finally get around to adding ODF's. Half the battle there is making interactive plots that don't look like garbage when embedded in a readthedocs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants