Visualizing data using the plot_slice function#
plot_slice
is a function that is capable of plotting 2-D datasets on axes which need not be orthogonal. This was designed originally for plotting X-ray scattering datasets much in the way that the NeXpy package does.
Importing plot_slice
#
from nxs_analysis_tools import plot_slice, load_data
from nexusformat.nexus import NXdata, NXfield
import numpy as np
Import data#
data_cubic = load_data('example_data/plot_slice_data/cubic_hkli.nxs')
data_hex = load_data('example_data/plot_slice_data/hex_hkli.nxs')
data:NXdata
@axes = ['H', 'K', 'L']
@signal = 'counts'
H = float64(100)
K = float64(150)
L = float64(200)
counts = float64(100x150x200)
data:NXdata
@axes = ['H', 'K', 'L']
@signal = 'counts'
H = float64(100)
K = float64(150)
L = float64(200)
counts = float64(100x150x200)
Basic plotting#
Plot slice accepts an NXdata
object which hold 2-D data. Thus, if working with a 3D scattering dataset, you must index one of the axes.
Here we plot the K=0 plane.
plot_slice(data_cubic[:,:,0.0])
<matplotlib.collections.QuadMesh at 0x7fa29e132650>
Transposing the X and Y axes#
plot_slice(data_cubic[:,:,0.0], transpose=True)
<matplotlib.collections.QuadMesh at 0x7fa29c0f1b40>
Plotting on non-orthogonal axes#
When working in a non-orthorhombic cell, it may be necessary to specify the skew angle between the axes of interest. Here, we consider a hexagonal crystal structure, for which H and K are 60$^\circ$ apart.
If we plot the data using no additional arugments, we see that the Bragg reflections are skewed.
plot_slice(data_hex[:,:,0])
<matplotlib.collections.QuadMesh at 0x7fa29be84ca0>
Use the skew_angle
parameter to correct the angle between the plotted X and Y axes.
plot_slice(data_hex[:,:,0], skew_angle=60)
<matplotlib.collections.QuadMesh at 0x7fa29a509690>
Adjusting axis limits#
Note that the x-axis limits are interpreted in a way that displays the full area covered by the specified x and y limits. Thus, when working with a skewed dataset, the actual tick marks on the x-axis will extend longer than the specified limits.
plot_slice(data_hex[:,:,0.0], skew_angle=60, xlim=(0,1), ylim=(0,1))
<matplotlib.collections.QuadMesh at 0x7fa29a408880>
Adjusting color mapping#
plot_slice(data_cubic[:,:,0.0], vmin=0,vmax=1)
<matplotlib.collections.QuadMesh at 0x7fa29a2ec610>
plot_slice(data_cubic[:,:,0.0], vmin=0,vmax=0.5)
<matplotlib.collections.QuadMesh at 0x7fa29a1dcfa0>
plot_slice(data_cubic[:,:,0.0], cmap='magma')
<matplotlib.collections.QuadMesh at 0x7fa29a0dd330>
Using logscale#
plot_slice(data_cubic[:,:,0.0], logscale=False)
<matplotlib.collections.QuadMesh at 0x7fa299fe0490>
plot_slice(data_cubic[:,:,0.0], logscale=True)
<matplotlib.collections.QuadMesh at 0x7fa299e6f880>
Using symlogscale#
First, let’s create a test dataset with both positive and negative values
data_sym = load_data('example_data/plot_slice_data/sym_hkli.nxs')
data:NXdata
@axes = ['H', 'K']
@signal = 'counts'
H = float64(100)
K = float64(150)
counts = float64(100x150)
Without the symlogscale
, the data is plotted on a linear colormap. Both a vmin
and vmax
can be provided for the limits of the colormap.
plot_slice(data_sym, cmap='seismic', symlogscale=False, vmin=-10, vmax=10)
<matplotlib.collections.QuadMesh at 0x7fa29a28b6d0>
With symlogscale
enabled, only the vmax
parameter is used the colorbar is symmetric about zero.
plot_slice(data_sym, cmap='seismic', symlogscale=True, vmax=10)
<matplotlib.collections.QuadMesh at 0x7fa299d654e0>