forked from IPKM/nmreval
remoce matplotlib import
This commit is contained in:
parent
48861c3f80
commit
bb3d5ac58b
@ -2,7 +2,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import pathlib
|
import pathlib
|
||||||
|
|
||||||
from matplotlib import pyplot as plt
|
|
||||||
# import matplotlib.pyplot as plt
|
# import matplotlib.pyplot as plt
|
||||||
from scipy.optimize import curve_fit
|
from scipy.optimize import curve_fit
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -219,16 +218,16 @@ class FCReader:
|
|||||||
np.savetxt(fit_path.joinpath(save_name), np.c_[xplot, yplot],
|
np.savetxt(fit_path.joinpath(save_name), np.c_[xplot, yplot],
|
||||||
header=header+'\t'.join([f'{p}+/-{err}' for p, err in zip(p0, perr)]))
|
header=header+'\t'.join([f'{p}+/-{err}' for p, err in zip(p0, perr)]))
|
||||||
|
|
||||||
if save_fig:
|
# if save_fig:
|
||||||
fig, ax = plt.subplots()
|
# fig, ax = plt.subplots()
|
||||||
ax.set_xlabel('t / s')
|
# ax.set_xlabel('t / s')
|
||||||
ax.set_ylabel('M')
|
# ax.set_ylabel('M')
|
||||||
axheader = f'T1: {p0[2]:.4g}(+/-{perr[2]:.4g}) beta: {p0[3]:.4g}(+/-{perr[3]:.4g})'
|
# axheader = f'T1: {p0[2]:.4g}(+/-{perr[2]:.4g}) beta: {p0[3]:.4g}(+/-{perr[3]:.4g})'
|
||||||
ax.set_title(f'f = {k:.4g} Hz\n{axheader}')
|
# ax.set_title(f'f = {k:.4g} Hz\n{axheader}')
|
||||||
ax.semilogx(v.x, v.y, 'o')
|
# ax.semilogx(v.x, v.y, 'o')
|
||||||
ax.semilogx(xplot, yplot, '-')
|
# ax.semilogx(xplot, yplot, '-')
|
||||||
fig.savefig(image_path.joinpath(save_name).with_suffix('.png'))
|
# fig.savefig(image_path.joinpath(save_name).with_suffix('.png'))
|
||||||
plt.close(fig)
|
# plt.close(fig)
|
||||||
|
|
||||||
freqs = np.asanyarray(freqs)
|
freqs = np.asanyarray(freqs)
|
||||||
params = np.asanyarray(params)
|
params = np.asanyarray(params)
|
||||||
@ -278,16 +277,16 @@ class FCReader:
|
|||||||
np.savetxt(save_path.joinpath(f'fitparameter_{key}.dat'), parameter,
|
np.savetxt(save_path.joinpath(f'fitparameter_{key}.dat'), parameter,
|
||||||
header=f'{key}\nM0\tM0_err\tOff\tOff_err\tT1\tT1_err\tbeta\tbeta_err')
|
header=f'{key}\nM0\tM0_err\tOff\tOff_err\tT1\tT1_err\tbeta\tbeta_err')
|
||||||
|
|
||||||
@staticmethod
|
# @staticmethod
|
||||||
def _plot_parameter(key, param, fig_mag, fig_t1, fig_beta):
|
# def _plot_parameter(key, param, fig_mag, fig_t1, fig_beta):
|
||||||
ax_mag = fig_mag.get_axes()[0]
|
# ax_mag = fig_mag.get_axes()[0]
|
||||||
ax_t1 = fig_t1.get_axes()[0]
|
# ax_t1 = fig_t1.get_axes()[0]
|
||||||
ax_beta = fig_beta.get_axes()[0]
|
# ax_beta = fig_beta.get_axes()[0]
|
||||||
|
#
|
||||||
pl, = ax_mag.plot(param[:, 0], param[:, 1], 'o', label=key)
|
# pl, = ax_mag.plot(param[:, 0], param[:, 1], 'o', label=key)
|
||||||
ax_mag.plot(param[:, 0], param[:, 3], 's', color=pl.get_color())
|
# ax_mag.plot(param[:, 0], param[:, 3], 's', color=pl.get_color())
|
||||||
ax_t1.plot(param[:, 0], param[:, 5], 'o', label=key)
|
# ax_t1.plot(param[:, 0], param[:, 5], 'o', label=key)
|
||||||
ax_beta.plot(param[:, 0], param[:, 7], 'o', label=key)
|
# ax_beta.plot(param[:, 0], param[:, 7], 'o', label=key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _save_parameter_plot(path, kind, fig_mag, fig_t1, fig_beta):
|
def _save_parameter_plot(path, kind, fig_mag, fig_t1, fig_beta):
|
||||||
@ -316,49 +315,49 @@ class FCReader:
|
|||||||
# plt.close(fig_beta)
|
# plt.close(fig_beta)
|
||||||
# plt.close(fig_t1)
|
# plt.close(fig_t1)
|
||||||
|
|
||||||
def plot_parameter(self, path, kind):
|
# def plot_parameter(self, path, kind):
|
||||||
path = pathlib.Path(path)
|
# path = pathlib.Path(path)
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
# path.mkdir(parents=True, exist_ok=True)
|
||||||
|
#
|
||||||
fig_mag, ax_mag = plt.subplots()
|
# fig_mag, ax_mag = plt.subplots()
|
||||||
fig_t1, ax_t1 = plt.subplots()
|
# fig_t1, ax_t1 = plt.subplots()
|
||||||
fig_beta, ax_beta = plt.subplots()
|
# fig_beta, ax_beta = plt.subplots()
|
||||||
|
#
|
||||||
if kind == 'temp':
|
# if kind == 'temp':
|
||||||
_params = self.t_params
|
# _params = self.t_params
|
||||||
else:
|
# else:
|
||||||
_params = self.f_params
|
# _params = self.f_params
|
||||||
|
#
|
||||||
save_path = path.joinpath(kind)
|
# save_path = path.joinpath(kind)
|
||||||
if not save_path.exists():
|
# if not save_path.exists():
|
||||||
save_path.mkdir(parents=True)
|
# save_path.mkdir(parents=True)
|
||||||
|
#
|
||||||
for key, par in _params.items():
|
# for key, par in _params.items():
|
||||||
pl, = ax_mag.plot(par[:, 0], par[:, 1], 'o', label=key)
|
# pl, = ax_mag.plot(par[:, 0], par[:, 1], 'o', label=key)
|
||||||
ax_mag.plot(par[:, 0], par[:, 3], 's', color=pl.get_color())
|
# ax_mag.plot(par[:, 0], par[:, 3], 's', color=pl.get_color())
|
||||||
ax_t1.plot(par[:, 0], par[:, 5], 'o', label=key)
|
# ax_t1.plot(par[:, 0], par[:, 5], 'o', label=key)
|
||||||
ax_beta.plot(par[:, 0], par[:, 7], 'o', label=key)
|
# ax_beta.plot(par[:, 0], par[:, 7], 'o', label=key)
|
||||||
|
#
|
||||||
for a in [ax_mag, ax_t1, ax_beta]:
|
# for a in [ax_mag, ax_t1, ax_beta]:
|
||||||
if kind == 'freq':
|
# if kind == 'freq':
|
||||||
a.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=2)
|
# a.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=2)
|
||||||
a.set_xlabel('T / K')
|
# a.set_xlabel('T / K')
|
||||||
else:
|
# else:
|
||||||
a.set_xscale('log')
|
# a.set_xscale('log')
|
||||||
a.legend(loc='upper left', bbox_to_anchor=(1, 1))
|
# a.legend(loc='upper left', bbox_to_anchor=(1, 1))
|
||||||
a.set_xlabel('f / Hz')
|
# a.set_xlabel('f / Hz')
|
||||||
|
#
|
||||||
ax_t1.set_yscale('log')
|
# ax_t1.set_yscale('log')
|
||||||
ax_t1.set_ylabel('T1 / s')
|
# ax_t1.set_ylabel('T1 / s')
|
||||||
ax_beta.set_ylabel('beta')
|
# ax_beta.set_ylabel('beta')
|
||||||
ax_mag.set_ylabel('M0 (squares), Offset (circles)')
|
# ax_mag.set_ylabel('M0 (squares), Offset (circles)')
|
||||||
|
#
|
||||||
fig_beta.savefig(path.joinpath(f'beta_{kind}.png'), bbox_inches="tight")
|
# fig_beta.savefig(path.joinpath(f'beta_{kind}.png'), bbox_inches="tight")
|
||||||
fig_mag.savefig(path.joinpath(f'mag_{kind}.png'), bbox_inches="tight")
|
# fig_mag.savefig(path.joinpath(f'mag_{kind}.png'), bbox_inches="tight")
|
||||||
fig_t1.savefig(path.joinpath(f't1_{kind}.png'), bbox_inches="tight")
|
# fig_t1.savefig(path.joinpath(f't1_{kind}.png'), bbox_inches="tight")
|
||||||
plt.close(fig_mag)
|
# plt.close(fig_mag)
|
||||||
plt.close(fig_beta)
|
# plt.close(fig_beta)
|
||||||
plt.close(fig_t1)
|
# plt.close(fig_t1)
|
||||||
|
|
||||||
def get_parameter(self, parameter='all', kind='freq', path=None, write=True, plot=True):
|
def get_parameter(self, parameter='all', kind='freq', path=None, write=True, plot=True):
|
||||||
param_list = []
|
param_list = []
|
||||||
|
Loading…
Reference in New Issue
Block a user