Plot guides › By field

Plot XAS spectra (XANES / EXAFS)

X-ray absorption spectra show the absorption coefficient μ(E) against photon energy around an element's absorption edge. Normalised spectra are overlaid to compare oxidation state and local structure, often with a zoom on the pre-edge.

Example plot xas spectra (xanes / exafs) made with matplotlib
Rendered from the code below, with example data.

When to use it

Ask for it in pltchat

Upload your file and type something like:

"overlay the normalised XANES spectra, zoom inset on the pre-edge 7110-7116 eV"

pltchat writes the loader and the plot for your columns, runs it in your browser and shows you the code.

The matplotlib code

Self-contained with example data; swap in pd.read_csv(...) or pd.read_excel(...) for your own file.

import numpy as np
import matplotlib.pyplot as plt

E = np.linspace(7090, 7200, 1200)          # eV, around the Fe K edge

def xanes(e0, white, pre):
    edge = 0.5 * (1 + np.tanh((E - e0) / 2.0))
    wl = white * np.exp(-0.5 * ((E - e0 - 6) / 4) ** 2)
    osc = 0.04 * np.sin((E - e0) / 9) * (E > e0 + 10)
    pe = pre * np.exp(-0.5 * ((E - 7113.5) / 1.0) ** 2)
    return edge + wl + osc + pe

spectra = {"Fe foil": xanes(7112, 0.05, 0.0), "FeO": xanes(7119, 0.35, 0.05),
           "Fe2O3": xanes(7123, 0.45, 0.09)}

fig, ax = plt.subplots(figsize=(6.4, 4))
inset = ax.inset_axes([0.55, 0.12, 0.4, 0.4])
for name, mu in spectra.items():
    ax.plot(E, mu, label=name)
    inset.plot(E, mu)
inset.set_xlim(7108, 7118)
inset.set_ylim(0, 0.35)
inset.set_title("pre-edge", fontsize=8)
inset.tick_params(labelsize=7)
ax.set_xlabel("Energy (eV)")
ax.set_ylabel("Normalised μ(E)")
ax.legend(loc="upper left")
plt.tight_layout()
plt.show()

Make this with your data

Upload a CSV, Excel, JSON or Parquet file. Your first plot is always free.

Related plots