nmreval/doc/examples/distribution/plot_KWW.py

51 lines
1.6 KiB
Python
Raw Normal View History

2022-03-22 19:07:59 +00:00
"""
=========================
Kohlrausch-Williams-Watts
=========================
Example for KWW distributions
"""
import matplotlib.pyplot as plt
import numpy as np
from nmreval.distributions import KWW
x = np.logspace(-5, 5, num=101)
kww = KWW
beta_KWW = [0.3, 0.5, 0.7]
fig, axes = plt.subplots(2, 3, constrained_layout=True)
lines = []
for b in beta_KWW:
axes[0, 0].plot(np.log10(x), kww.correlation(x, 1, b))
axes[1, 0].plot(np.log10(x), np.log10(kww.specdens(x, 1, b)))
axes[0, 1].plot(np.log10(x), np.log10(kww.susceptibility(x, 1, b).real))
axes[1, 1].plot(np.log10(x), np.log10(kww.susceptibility(x, 1, b).imag))
l, = axes[0, 2].plot(np.log10(x), kww.distribution(x, 1, b),
label=rf'$\beta={b}$')
lines.append(l)
fig_titles = ('Correlation function', 'Susceptibility (real)', 'Distribution',
'Spectral density', 'Susceptibility (imag)')
fig_xlabel = (r'$\log(t/\tau_\mathrm{KWW})$', r'$\log(\omega\tau_\mathrm{KWW})$',
r'$\log(\tau/\tau_\mathrm{KWW})$', r'$\log(\omega\tau_\mathrm{KWW})$',
r'$\log(\omega\tau_\mathrm{KWW})$')
fig_ylabel = (r'$C(t)$', r"$\log(\chi'(\omega))$", r'$G(\ln\tau)$',
r'$\log(J(\omega))$', r"$\log(\chi''(\omega))$")
for title, xlabel, ylabel, ax in zip(fig_titles, fig_xlabel, fig_ylabel, axes.ravel()):
ax.set_title(title)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
labels = [l.get_label() for l in lines]
leg = fig.legend(lines, labels, loc='center left', bbox_to_anchor=(1.05, 0.50),
bbox_transform=axes[1, 1].transAxes)
fig.delaxes(axes[1, 2])
plt.show()