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>
../_images/e79948d5ea234b05d21d0b13d2704fe14228a29596419b3823add2b5d9a8bd1e.png

Transposing the X and Y axes#

plot_slice(data_cubic[:,:,0.0], transpose=True)
<matplotlib.collections.QuadMesh at 0x7fa29c0f1b40>
../_images/c22eefef3e202f7d47d36dc410e74456f04ab830132f140e935d6238f377356b.png

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>
../_images/e674a62f1aa00ad152c4a94a37ca22599f20999dda164cbceb3f4c5e7d8d1a93.png

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>
../_images/10436c6cadc59ac54a1a9b19df9f7cd2a79628f8ad319fda9e45c1fba4048dd2.png

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>
../_images/a84f5ea94f0887c67e8b398ae1bb0cef55e39f6bc52541cdcab79270bddd649d.png

Adjusting color mapping#

plot_slice(data_cubic[:,:,0.0], vmin=0,vmax=1)
<matplotlib.collections.QuadMesh at 0x7fa29a2ec610>
../_images/5859eefe27ae48af2fe40907d5a7d7935e804e072d1d7fb85bcc58d602a91e3e.png
plot_slice(data_cubic[:,:,0.0], vmin=0,vmax=0.5)
<matplotlib.collections.QuadMesh at 0x7fa29a1dcfa0>
../_images/d1130825786e260ab225f7a4b477fc4b5721d4bdb1bd62812165176f17e3f445.png
plot_slice(data_cubic[:,:,0.0], cmap='magma')
<matplotlib.collections.QuadMesh at 0x7fa29a0dd330>
../_images/113f5c1ca7c6145252d7b98386a8e14565dd19badd72af057d962c6730b3f4cf.png

Using logscale#

plot_slice(data_cubic[:,:,0.0], logscale=False)
<matplotlib.collections.QuadMesh at 0x7fa299fe0490>
../_images/e79948d5ea234b05d21d0b13d2704fe14228a29596419b3823add2b5d9a8bd1e.png
plot_slice(data_cubic[:,:,0.0], logscale=True)
<matplotlib.collections.QuadMesh at 0x7fa299e6f880>
../_images/e0e9cf415104352379b0f2f8be9445d99ce7e614eb93b53aeddb13afffe70844.png

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>
../_images/28bc56530d7ae467ebe522501a896445d7afcadf1f82f8b9f1c01d712c9f6561.png

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>
../_images/61102c9a7846a375e44fd70ae049d41de5321c9b58f7b058ca09b1b0df473bb3.png