Note
Go to the end to download the full example code.
Fast Plotting Tricks#
Sometimes you want to quickly plot a diffraction pattern but things seem slow, this mostly happens with “large” data that is loaded Lazily.
There are a couple of different ways that plotting in hyperspy/pyxem can be slow:
The data is too large and the navigator is being recalculated every time you plot. (i.e. calling s.plot()
takes a long time to render)
Dragging the navigator is slow and laggy.
from pyxem.data import fe_multi_phase_grains
import numpy as np
import hyperspy.api as hs
s = fe_multi_phase_grains().as_lazy()
Using the QT Backend and Blitting#
To solve the second problem, you can:
1. Use the Qt backend by running %matplotlib qt in a Jupyter notebook cell. This will make the navigator much more responsive using “blitting” which only updates the parts of the plot that have changed. Note that the QT backend is not available in Google Colab or when running in a Jupyter notebook on a remote server.
Using Shift + Click to Jump#
2. You can use the Shift + Click feature to “Jump” to a specific location in the navigator. This is useful if you want to quickly move to a specific location in the navigator without dragging the navigator and loading all the data in between.
You can also set the navigator point using the axes_manager.indices attribute.
s.axes_manager.indices = (5, 5) # jump to the center of the navigator
s.plot()
Saving the Data#
4. Finally, you can always consider saving the data in a more performant format like .zspy This will make loading the data faster which will in turn make plotting faster!
/home/docs/checkouts/readthedocs.org/user_builds/pyxem/envs/1139/lib/python3.11/site-packages/rsciio/zspy/_api.py:215: FutureWarning: The NestedDirectoryStore is deprecated and will be removed in a Zarr-Python version 3, see https://github.com/zarr-developers/zarr-python/issues/1274 for more information.
store = zarr.storage.NestedDirectoryStore(
[ ] | 0% Completed | 194.67 us
[ ] | 0% Completed | 100.36 ms
[########################################] | 100% Completed | 200.78 ms
Total running time of the script: (0 minutes 1.346 seconds)