pyxem / orix

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

Pole Density Function #484

Open maclariz opened 2 months ago

maclariz commented 2 months ago

Just had some fun with pole density function today, but I found an issue with documentation and I have a question.

First the issue: This page has plotting into an existing figure: https://orix.readthedocs.io/en/stable/tutorials/pole_density_function.html But this page doesn't even mention a "figure" argument you can call: https://orix.readthedocs.io/en/stable/reference/generated/orix.measure.pole_density_function.html

Secondly, the question: Can I use this function to plot within an existing defined axis within a multiple axis figure (e.g. created with plt.subplots)?

harripj commented 2 months ago

@maclariz you're right. The measure.pole_density_function function performs the computation and returns the histogram data and edges, and is useful for accessing the data or performing further processing on the histogram data.

There is a similarly named function (perhaps confusingly) StereographicPlot.pole_density_function which is essentially a convenience function around measure.pole_density_function mentioned above, and can be used to quickly produce a plot. You can see this in the code here. (There is also a density plot for the inverse pole figure).

To answer your second point, yes absolutely. There are a couple examples in the tutorial you linked above. You just need to define the subplot projection as stereographic to use the StereographicPlot functions.

Here is an example with an independent plot (note that the orix.plot import is necessary to register the projection within Matplotlib):

import orix.plot
from orix.vector import Vector3d

import numpy as np
import matplotlib.pyplot as plt

v = Vector3d(np.random.randn(1_000, 3))

fig = plt.figure(figsize=(10, 5))
ax1 = fig.add_subplot(121, projection="stereographic")
ax2 = fig.add_subplot(122)

ax1.pole_density_function(v)
x = np.arange(10)
ax2.plot(x, x**2)

image

hakonanes commented 2 months ago

This should be added to the examples gallery!

maclariz commented 2 months ago

Thanks. This is helpful. Will use this. Sorry for late reply, was travelling on a different project.