Skip to content

Quaternions plot incorrectly (but also maybe shouldn't plot at all). #683

Description

@argerlt

A simple problem with two simple solutions, the choice just depends on if we think ax.scatter(oqu.Quaternion) should be allowed.

If you run this code:

import matplotlib.pyplot as plt
import numpy as np
import orix.plot as opl
import orix.quaternion as oqu
opl.register_projections()

# NOTE, this is a Quaternion, not a Rotation/Misorientation
q = oqu.Quaternion.random(1000)

fig = plt.figure()
ax = fig.add_subplot(111,projection='homochoric')

# plot the quaternion, which gets misinterpreted as a Vector3D by RotationPlot
ax.scatter(q)

# Plot C1 fundamental zone and clean up plot to help with visualization.
fz =oqu.OrientationRegion.from_symmetry(oqu.symmetry.C1)
ax.plot_wireframe(fz)
ax.set_aspect('equal')
ax.axis('off')

You would expect a cloud of points filling an orb with the same radius as the C1 fundamental zone. Instead though, you get this:
Image

This is because the logic in orix.plot.rotation_plot.RotationPlot.transform() checks if the input is a Rotation, and if it isn't but it is an Object3d, it assume it's a Vector3D. The end result being that [q.a,q.b,q.c] from a quaternion are recast as the xyz of a Vector3D and the qd is discarded. since qa>0, the resulting plot is also a half-circle.

Solution 1: Quaternions should be plottable

If we think a quaternion should be plottable, we just change line 80 of orix.plot.rotatoin_plot.RotationPlot.transform() from

        if isinstance(xs, Rotation):

to

        if isinstance(xs, Quaternion):

which adds capability but might cause a problem if a later function assumes all plot elements have an improper attribute,

Solution 1: Quaternions should NOT be plottable

If we think quaternions should not be plotted directly, we add an extra elif isinstance(xs, Quaternion) catch that raises an error.

Either way, I can add this to a PR along with unit tests, I just want a second person's input.

After typing this out, I'm leading vaguely to Solution 2 just to avoid a future edge case, but I could be convinced to either way

Thoughts?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttheoryThis issue has a non-technical element

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions