mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 19:43:41 +02:00
removed plot_corrs
This commit is contained in:
parent
a93944cf27
commit
950cd13c07
1 changed files with 0 additions and 118 deletions
|
@ -1106,124 +1106,6 @@ def load_object(path):
|
||||||
return pickle.load(file)
|
return pickle.load(file)
|
||||||
|
|
||||||
|
|
||||||
def plot_corrs(observables, **kwargs):
|
|
||||||
"""Plot lists of Obs.
|
|
||||||
|
|
||||||
Parameters
|
|
||||||
----------
|
|
||||||
observables -- list of lists of Obs, where the nth entry is considered to be the
|
|
||||||
correlation function
|
|
||||||
at x0=n e.g. [[f_A_0,f_A_1],[f_P_0,f_P_1]] or [f_A,f_P], where f_A and f_P are lists of Obs.
|
|
||||||
|
|
||||||
Keyword arguments
|
|
||||||
-----------------
|
|
||||||
xrange -- list of two values, determining the range of the x-axis e.g. [4, 8]
|
|
||||||
yrange -- list of two values, determining the range of the y-axis e.g. [0.2, 1.1]
|
|
||||||
prange -- list of two values, visualizing the width of the plateau e.g. [10, 15]
|
|
||||||
reference -- float valued variable which is shown as horizontal line for reference
|
|
||||||
plateau -- Obs which is shown as horizontal line with errorbar for reference
|
|
||||||
shift -- shift x by given value
|
|
||||||
label -- list of labels, has to have the same length as observables
|
|
||||||
exp -- plot exponential from fitting routine
|
|
||||||
"""
|
|
||||||
|
|
||||||
if 'shift' in kwargs:
|
|
||||||
shift = kwargs.get('shift')
|
|
||||||
else:
|
|
||||||
shift = 0
|
|
||||||
|
|
||||||
if 'label' in kwargs:
|
|
||||||
label = kwargs.get('label')
|
|
||||||
if len(label) != len(observables):
|
|
||||||
raise Exception('label has to be a list with exactly one entry per entry of observables.')
|
|
||||||
else:
|
|
||||||
label = []
|
|
||||||
for j in range(len(observables)):
|
|
||||||
label.append(str(j + 1))
|
|
||||||
|
|
||||||
|
|
||||||
f = plt.figure()
|
|
||||||
for j in range(len(observables)):
|
|
||||||
T = len(observables[j])
|
|
||||||
|
|
||||||
x = np.arange(T) + shift
|
|
||||||
y = np.zeros(T)
|
|
||||||
y_err = np.zeros(T)
|
|
||||||
|
|
||||||
for i in range(T):
|
|
||||||
y[i] = observables[j][i].value
|
|
||||||
y_err[i] = observables[j][i].dvalue
|
|
||||||
|
|
||||||
plt.errorbar(x, y, yerr=y_err, ls='none', fmt='o', capsize=3,
|
|
||||||
markersize=5, lw=1, label=label[j])
|
|
||||||
|
|
||||||
if kwargs.get('logscale'):
|
|
||||||
plt.yscale('log')
|
|
||||||
|
|
||||||
if 'xrange' in kwargs:
|
|
||||||
xrange = kwargs.get('xrange')
|
|
||||||
plt.xlim(xrange[0], xrange[1])
|
|
||||||
visible_y = y[int(xrange[0] + 0.5):int(xrange[1] + 0.5)]
|
|
||||||
visible_y_err = y_err[int(xrange[0] + 0.5):int(xrange[1] + 0.5)]
|
|
||||||
y_start = np.min(visible_y - visible_y_err)
|
|
||||||
y_stop = np.max(visible_y + visible_y_err)
|
|
||||||
span = y_stop - y_start
|
|
||||||
if np.isfinite(y_start) and np.isfinite(y_stop):
|
|
||||||
plt.ylim(y_start - 0.1 * span, y_stop + 0.1 * span)
|
|
||||||
|
|
||||||
if 'yrange' in kwargs:
|
|
||||||
yrange = kwargs.get('yrange')
|
|
||||||
plt.ylim(yrange[0], yrange[1])
|
|
||||||
|
|
||||||
if 'reference' in kwargs:
|
|
||||||
y_value = kwargs.get('reference')
|
|
||||||
plt.axhline(y=y_value, linewidth=2, color='k', alpha=0.25)
|
|
||||||
|
|
||||||
if 'prange' in kwargs:
|
|
||||||
prange = kwargs.get('prange')
|
|
||||||
plt.axvline(x=prange[0] - 0.5, ls='--', c='k', lw=1, alpha=0.5, marker=',')
|
|
||||||
plt.axvline(x=prange[1] + 0.5, ls='--', c='k', lw=1, alpha=0.5, marker=',')
|
|
||||||
|
|
||||||
if 'plateau' in kwargs:
|
|
||||||
plateau = kwargs.get('plateau')
|
|
||||||
if isinstance(plateau, Obs):
|
|
||||||
plt.axhline(y=plateau.value, linewidth=2, color='k', alpha=0.6, label='Plateau', marker=',', ls='--')
|
|
||||||
plt.axhspan(plateau.value - plateau.dvalue, plateau.value + plateau.dvalue, alpha=0.25, color='k')
|
|
||||||
elif isinstance(plateau, list):
|
|
||||||
for i in range(len(plateau)):
|
|
||||||
plt.axhline(y=plateau[i].value, linewidth=2, color='C' + str(i), alpha=0.6, label='Plateau' + str(i + 1), marker=',', ls='--')
|
|
||||||
plt.axhspan(plateau[i].value - plateau[i].dvalue, plateau[i].value + plateau[i].dvalue,
|
|
||||||
color='C' + str(i), alpha=0.25)
|
|
||||||
else:
|
|
||||||
raise Exception('Improper input for plateau.')
|
|
||||||
|
|
||||||
if kwargs.get('exp'):
|
|
||||||
fit_result = kwargs.get('exp')
|
|
||||||
y_fit = fit_result[1].value * np.exp(-fit_result[0].value * x)
|
|
||||||
plt.plot(x, y_fit, color='k')
|
|
||||||
if not (fit_result[0].e_names == {} and fit_result[1].e_names == {}):
|
|
||||||
y_fit_err = np.sqrt((y_fit * fit_result[0].dvalue) ** 2 + 2 * covariance(fit_result[0], fit_result[1])* y_fit *
|
|
||||||
np.exp(-fit_result[0].value * x) + (np.exp(-fit_result[0].value * x) * fit_result[1].dvalue) ** 2)
|
|
||||||
plt.fill_between(x, y_fit + y_fit_err, y_fit - y_fit_err, color='k', alpha=0.1)
|
|
||||||
|
|
||||||
plt.xlabel('$x_0/a$')
|
|
||||||
|
|
||||||
if 'ylabel' in kwargs:
|
|
||||||
plt.ylabel(kwargs.get('ylabel'))
|
|
||||||
|
|
||||||
if 'save' in kwargs:
|
|
||||||
lgd = plt.legend(loc=0)
|
|
||||||
else:
|
|
||||||
lgd = plt.legend(bbox_to_anchor=(1.04, 1), loc='upper left')
|
|
||||||
plt.show()
|
|
||||||
|
|
||||||
if 'save' in kwargs:
|
|
||||||
save = kwargs.get('save')
|
|
||||||
if not isinstance(save, str):
|
|
||||||
raise Exception('save has to be a string.')
|
|
||||||
f.savefig(save + '.pdf', bbox_extra_artists=(lgd,), bbox_inches='tight')
|
|
||||||
|
|
||||||
|
|
||||||
def merge_obs(list_of_obs):
|
def merge_obs(list_of_obs):
|
||||||
"""Combine all observables in list_of_obs into one new observable
|
"""Combine all observables in list_of_obs into one new observable
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue