Plotting#

You can plot datasets using xarray.DataArray.epoch.plot. This is a custom sdf_xarray plotting routine that builds on top of xarray.DataArray.plot, so you keep the familiar xarray plotting behaviour while using sdf_xarray conveniences (see here for details). Under the hood, plotting is still handled by matplotlib, which means you can use the full matplotlib API to customise your figure.

Dimensions

Base plotting function

Notes

1

xarray.plot.line

2

xarray.plot.pcolormesh

3

mpl_toolkits.mplot3d.axes3d.Axes3D.voxels

Custom functionality built for sdf_xarray

>3

xarray.plot.hist

Not fully implemented

Line plots#

One dimensional data will be plotted as a line. Multiple lines can be easily plotted at the same time.

import sdf_xarray as sdfxr
import matplotlib.pyplot as plt
ds = sdfxr.open_dataset("tutorial_dataset_1d/0010.sdf")
da_1 = ds["Derived_Number_Density_Electron"]
da_2 = ds["Derived_Number_Density_Ion"]
da_1.epoch.plot(label = "Electron")
da_2.epoch.plot(label = "Ion")
plt.legend()
plt.show()
_images/7941c4c9528f071a61d36082125f9f51e91522a919c1d8f40461289ca361fee1.png

Mesh plots#

Two dimensional data will be plotted as a mesh.

ds = sdfxr.open_dataset("tutorial_dataset_2d/0010.sdf")
da = ds["Derived_Number_Density_Electron"]
da.epoch.plot()
plt.show()
_images/5571dfe87218eca17e1ceb1e88be4707163ba5e27631b3aa69bb32b7508a7ff1.png

Voxel plots#

Three dimensional data will be plotted using voxels. This behaviour is not native to xarray, it has been custom built specifically for this package.

ds = sdfxr.open_dataset("tutorial_dataset_3d/0000.sdf")
da = ds["Derived_Number_Density"]
da.epoch.plot(vmin = 1e27)
plt.show()

voxel_plot_high_res

Warning

Voxel plots can be extremely computationally expensive and may take longer than expected to plot.

Because voxel plots are very expensive, even with relatively small data arrays, plotting can be sped up by using xarray.DataArray.epoch.resize, which uses interpolation to reduce the resolution.

ds = sdfxr.open_dataset("tutorial_dataset_3d/0005.sdf")
da = ds["Derived_Number_Density"]
da_resized = da.epoch.resize((20, 20, 20))
da_resized.epoch.plot(vmin = 1e27)
plt.show()
/home/docs/checkouts/readthedocs.org/user_builds/sdf-xarray/checkouts/v0.9.0/src/sdf_xarray/dataarray_accessor.py:87: UserWarning: Voxel plots can be extremely computationally expensive and may take longer than expected to plot.
  return voxel_plot(self._obj, *args, **kwargs)
_images/387e45cd9ba4ded40ffda89ab391064dd17d56a3cb369b89d5076bdd88f984f2.png

Histograms#

When the data array has four or more dimensions (or is specified by the user), it will be plotted as a histogram.

ds = sdfxr.open_dataset("tutorial_dataset_3d/0005.sdf")
da = ds["Derived_Number_Density"]

da.epoch.plot(hist = True)
plt.show()
_images/fa47a7e91ee0f85c44ae9bc55cb8ee618c69982d3c510d1c174624a738f05908.png