NHT changes plots combined fit (#166)

* NHT changes plots combined fit

* feat: Exception for illegal combination added and test fixed.

---------

Co-authored-by: Fabian Joswig <fabian.joswig@ed.ac.uk>
This commit is contained in:
nils-ht 2023-03-17 13:52:07 +00:00 committed by GitHub
parent 83204ce794
commit 2363b755dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 4 deletions

View file

@ -788,7 +788,7 @@ class Corr:
self.prange = prange
return
def show(self, x_range=None, comp=None, y_range=None, logscale=False, plateau=None, fit_res=None, ylabel=None, save=None, auto_gamma=False, hide_sigma=None, references=None, title=None):
def show(self, x_range=None, comp=None, y_range=None, logscale=False, plateau=None, fit_res=None, fit_key=None, ylabel=None, save=None, auto_gamma=False, hide_sigma=None, references=None, title=None):
"""Plots the correlator using the tag of the correlator as label if available.
Parameters
@ -804,6 +804,8 @@ class Corr:
Plateau value to be visualized in the figure.
fit_res : Fit_result
Fit_result object to be visualized.
fit_key : str
Key for the fit function in Fit_result.fit_function (for combined fits).
ylabel : str
Label for the y-axis.
save : str
@ -883,9 +885,13 @@ class Corr:
if fit_res:
x_samples = np.arange(x_range[0], x_range[1] + 1, 0.05)
ax1.plot(x_samples,
fit_res.fit_function([o.value for o in fit_res.fit_parameters], x_samples),
ls='-', marker=',', lw=2)
if isinstance(fit_res.fit_function, dict):
if fit_key:
ax1.plot(x_samples, fit_res.fit_function[fit_key]([o.value for o in fit_res.fit_parameters], x_samples), ls='-', marker=',', lw=2)
else:
raise ValueError("Please provide a 'fit_key' for visualizing combined fits.")
else:
ax1.plot(x_samples, fit_res.fit_function([o.value for o in fit_res.fit_parameters], x_samples), ls='-', marker=',', lw=2)
ax1.set_xlabel(r'$x_0 / a$')
if ylabel: