Plot module

The plot module offers classes and functions to preset Matplotlib axes for plotting XAS spectra. The following functions are currently implemented:

Function

Description

fig_xas_template()

Presets a plot of XAS spectra.

fig_merge()

Plot the results of a merge operation.

fig_pre_edge()

Plot the results of pre-edge substraction and normalization.

fig_autobk()

Plot the results of background removal.

fig_cluster()

Plots the dendrogram of a hierarchical clustering.

fig_pca()

Plots the results of principal component analysis.

fig_target_transform()

Plots the results of target transformation.

fig_lcf()

Plot the results of a linear combination fit.

class araucaria.plot.template.FigPars[source]

Class dictionary with argument for plotting functions.

This utility class stores arguments to preset Matplotlib axes.

Parameters
  • prop_cycle (list) – List of property cycle dictionaries for each axes. List is iterated if the elements of the list are less than the number of panels. See the set_prop_cycle() method for further details.

  • e_range (list) – XANES energy range.

  • e_ticks (list) – XANES energy tick marks.

  • mu_range (list) – XANES norm. abs. range.

  • mu_ticks (list) – XANES norm. abs. tick marks.

  • dmu_range (list) – XANES deriv norm. abs. range.

  • dmu_ticks (list) – XANES deriv norm. abs. tick marks.

  • kweight (int) – EXAFS k-weight.

  • k_range (list) – EXAFS wavenumber range.

  • k_ticks (list) – EXAFS wavenumber tick marks.

  • chi_range (list) – EXAFS chi(k) range.

  • chi_ticks (list) – EXAFS chi(k) tick marks.

  • r_range (list) – FT-EXAFS R range.

  • r_ticks (list) – FT-EXAFS R tick marks.

  • chir_range (list) – FT-EXAFS magnitude range.

  • chir_ticks (list) – FT-EXAFS magnitude tick marks.

  • q_range (list) – reverse FT-EXAFS wavenumber range.

  • q_ticks (list) – reverse FT-EXAFS wavenumber tick marks.

araucaria.plot.template.fig_xas_template(panels='xx', fig_pars=None, **fig_kws)[source]

Returns a preset Matplotlib figure and axes object to plot XAS spectra.

Panel elements (axes) are indexed in row-major (C-style order).

Parameters
  • panels (str) –

    Panels to plot. Valid arguments are as follows:

    • ’d’ : Derivative of XANES spectra.

    • ’x’ : XANES spectra.

    • ’e’ : EXAFS spectra.

    • ’r’ : FT-EXAFS spectra.

    • ’q’ : Reverse FT-EXAFS spectra.

    • ’u’ : Unassigned pannel.

    • ’/’ : Character for a new row.

    The characters can be concatenated to produce multiple panels and rows. Examples: ‘dxe’, ‘xx’, ‘xer’, ‘xx/xx’.

  • fig_pars (Optional[FigPars]) – Dictionary arguments for the figure. See FigPars for details.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises
  • ValueError – If number of columns and rows do not match in panels.

  • ValueError – If requested panel type in panels is not recognized.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.plot import fig_xas_template
>>> pars = {'e_range' : (0,100),
...         'mu_range': (0,1.5),
...         'k_range' : (0,15),
...         'r_range' : (0,6)}
>>> fig, axes = fig_xas_template('dx/er', fig_pars=pars)
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-1.png
araucaria.plot.fig_xas.fig_merge(merge, collection, pre_edge_kws=None, autobk_kws=None, fig_pars=None, **fig_kws)[source]

Plots the results of a merge operation in a collection.

Parameters
  • merge (Group) – Group with the merged scan.

  • collection (Collection) – Collection with the merged groups.

  • pre_edge_kws (Optional[dict]) – Dictionary with arguments for normalization.

  • autobk_kws (Optional[dict]) – Dictionary with arguments for background removal.

  • fig_pars (Optional[FigPars]) – Dictionary arguments for the figure. See FigPars for details.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises
  • TypeError – If collection is not a valid Collection instance.

  • TypeError – If merge is not a valid Group instance.

  • AttributeError – If attribute merged_scans does not exist in merge.

  • AttributeError – If attribute merged_scans does not exist in any of the groups in collection.

Notes

The returned plot contains the original signals and merged signal in both normalized \(\mu(E)\) and \(\chi(k)\).

Important

Optional arguments such as pre_edge_kws and autobk_kws are used to calculate the normalized \(\mu(E)\) and \(\chi(k)\) signals. Such parameters have no effect on the merge operation.

By default legends are not included in the figure. However they can be requested for any axis (see Example).

See also

merge()

Merge groups in a collection.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria import Collection
>>> from araucaria.testdata import get_testpath
>>> from araucaria.io import read_dnd
>>> from araucaria.xas import merge
>>> from araucaria.plot import fig_merge
>>> collection = Collection()
>>> files = ['dnd_testfile1.dat' , 'dnd_testfile2.dat', 'dnd_testfile3.dat']
>>> for file in files:
...     fpath = get_testpath(file)
...     group_mu = read_dnd(fpath, scan='mu')  # extracting mu and mu_ref scans
...     collection.add_group(group_mu)         # adding group to collection
>>> report, merge = merge(collection)
>>> fig, ax = fig_merge(merge, collection)
>>> leg     = ax[0].legend(fontsize=8)
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-2.png
araucaria.plot.fig_xas.fig_pre_edge(group, show_pre_edge=True, show_post_edge=True, fig_pars=None, **fig_kws)[source]

Plots the results of pre-edge substraction and normalization of a data group.

Parameters
  • group (Group) – Group with the normalized scan.

  • show_pre_edge (bool) – Indicates if the pre-edge fit curve should be plotted. The detault is True.

  • show_post_edge (bool) – Indicates if the post-edge fit curve should be plotted. The detault is True.

  • fig_pars (Optional[FigPars]) – Dictionary arguments for the figure. See FigPars for details.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises

Notes

The returned plot contains the original \(\mu(E)\), the adjusted pre-edge and post-edge curves (optional), and the normalized and flattened \(\mu(E)\).

See also

pre_edge()

Pre-edge substaction and normalization of a scan.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.testdata import get_testpath
>>> from araucaria.io import read_dnd
>>> from araucaria.xas import pre_edge
>>> from araucaria.plot import fig_pre_edge
>>> fpath   = get_testpath('dnd_testfile1.dat')
>>> group   = read_dnd(fpath, scan='mu')
>>> pre     = pre_edge(group, update=True)
>>> fig, ax = fig_pre_edge(group)
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-3.png
araucaria.plot.fig_xas.fig_autobk(group, show_window=True, fig_pars=None, **fig_kws)[source]

Plots the results of background removal for a data group.

Parameters
  • group (Group) – Group with the normalized scan.

  • show_window (bool) – Indicates if the FT-window should be plotted. The detault is True.

  • fig_pars (Optional[FigPars]) – Dictionary arguments for the figure. See FigPars for details.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises

See also

autobk()

Background removal of a scan.

Notes

The returned plot contains the original \(\mu(E)\) and the background function, as well as the resulting \(\chi(k)\).

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.testdata import get_testpath
>>> from araucaria.io import read_dnd
>>> from araucaria.xas import pre_edge, autobk
>>> from araucaria.plot import fig_autobk
>>> fpath   = get_testpath('dnd_testfile1.dat')
>>> group   = read_dnd(fpath, scan='mu')
>>> pre     = pre_edge(group, update=True)
>>> bkg     = autobk(group, update=True)
>>> fig, ax = fig_autobk(group, show_window=False)
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-4.png
araucaria.plot.fig_stats.fig_cluster(out, fontsize=8, **fig_kws)[source]

Plots the dendrogram of a hierarchical clustering.

Parameters
  • out (Dataset) – Valid Dataset from cluster().

  • fontsize (float) – Font size for labels. The default is 8.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises

See also

cluster()

Performs hierarchical clustering on a collection.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.testdata import get_testpath
>>> from araucaria.xas import pre_edge
>>> from araucaria.stats import cluster
>>> from araucaria.io import read_collection_hdf5
>>> from araucaria.plot import fig_cluster
>>> fpath      = get_testpath('Fe_database.h5')
>>> collection = read_collection_hdf5(fpath)
>>> collection.apply(pre_edge)
>>> datgroup   = cluster(collection, cluster_region='xanes')
>>> fig, ax    = fig_cluster(datgroup)
>>> fig.tight_layout()
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-5.png
araucaria.plot.fig_stats.fig_pca(model, fontsize=8, **fig_kws)[source]

Plots the results of principal component analysis (PCA) on a collection.

Parameters
  • model (PCAModel) – Valid PCAModel from pca().

  • fontsize (float) – Font size for labels. The default is 8.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises
  • TypeError – If model is not a valid PCAModel instance

  • KeyError – If attributes from pca() do not exist in model.

See also

pca()

Performs principal component analysis on a collection.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.testdata import get_testpath
>>> from araucaria.xas import pre_edge
>>> from araucaria.stats import pca
>>> from araucaria.io import read_collection_hdf5
>>> from araucaria.plot import fig_pca
>>> fpath      = get_testpath('Fe_database.h5')
>>> collection = read_collection_hdf5(fpath)
>>> collection.apply(pre_edge)
>>> model      = pca(collection, pca_region='xanes',
...                  pca_range=[7050, 7300])
>>> fig, axes = fig_pca(model, fontsize=8)
>>> fig.tight_layout()
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-6.png
araucaria.plot.fig_stats.fig_target_transform(out, model, sorted=True, fontsize=8, **fig_kws)[source]

Plots the results of target transformation on a collection.

Parameters
  • out (Dataset) – Valid Dataset from target_transform().

  • model (PCAModel) – Valid PCA model from pca().

  • sorted (bool) – Conditional for plotting target transformations from lowest to highest chi-square. The default is True.

  • fontsize (float) – Font size for labels. The default is 8.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises

See also

pca()

Performs principal component analysis on a collection.

target_transform()

Performs target transformation on a collection.

Example

>>> import matplotlib.pyplot as plt
>>> from araucaria.testdata import get_testpath
>>> from araucaria import Dataset
>>> from araucaria.io import read_collection_hdf5
>>> from araucaria.xas import pre_edge
>>> from araucaria.stats import pca, target_transform
>>> from araucaria.plot import fig_target_transform
>>> fpath      = get_testpath('Fe_database.h5')
>>> collection = read_collection_hdf5(fpath)
>>> collection.apply(pre_edge)
>>> model      = pca(collection, pca_region='xanes', ncomps=3,
...                  pca_range=[7050,7300])
>>> data       = target_transform(model, collection)
>>> fig, axes  = fig_target_transform(data, model)
>>> legend     = axes[0,0].legend(loc='upper right', edgecolor='k')
>>> fig.tight_layout()
>>> plt.show(block=False)

(Source code, png, hires.png, pdf)

_images/plot_module-7.png
araucaria.plot.fig_lcf.fig_lcf(out, offset=0.5, annotate=True, fontsize=8, fig_pars=None, **fig_kws)[source]

Plots the results of linear combination fit (LCF) on a collecton.

Parameters
  • out (Dataset) – Valid Dataset from lcf().

  • offset (float) – Offset step value for plots. The default is 0.5.

  • annotate (bool) – Indicates if the plot should be annotated. The detault is True

  • fontsize (float) – Font size for annotations. The default is 8.

  • fig_pars (Optional[FigPars]) – Dictionary arguments for the figure. See FigPars for details.

  • fig_kws (dict) – Additional arguments to pass to the subplots() routine of Matplotlib.

Return type

Tuple[Figure, Axes]

Returns

  • figureMatplolib figure object.

  • axesMatplotlib axes object.

Raises