Merge branch 'develop' into documentation

This commit is contained in:
fjosw 2022-02-16 11:58:11 +00:00
commit 3025584536

View file

@ -689,8 +689,8 @@ class Corr:
self.prange = prange self.prange = prange
return return
def show(self, x_range=None, comp=None, y_range=None, logscale=False, plateau=None, fit_res=None, ylabel=None, save=None): 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):
"""Plots the correlator, uses tag as label if available. """Plots the correlator using the tag of the correlator as label if available.
Parameters Parameters
---------- ----------
@ -698,19 +698,26 @@ class Corr:
list of two values, determining the range of the x-axis e.g. [4, 8] list of two values, determining the range of the x-axis e.g. [4, 8]
comp : Corr or list of Corr comp : Corr or list of Corr
Correlator or list of correlators which are plotted for comparison. Correlator or list of correlators which are plotted for comparison.
The tags of these correlators are used as labels if available.
logscale : bool logscale : bool
Sets y-axis to logscale Sets y-axis to logscale
plateau : Obs plateau : Obs
plateau to be visualized in the figure Plateau value to be visualized in the figure
fit_res : Fit_result fit_res : Fit_result
Fit_result object to be visualized Fit_result object to be visualized
ylabel : str ylabel : str
Label for the y-axis Label for the y-axis
save : str save : str
path to file in which the figure should be saved path to file in which the figure should be saved
auto_gamma : bool
Apply the gamma method with standard parameters to all correlators and plateau values before plotting.
""" """
if self.N != 1: if self.N != 1:
raise Exception("Correlator must be projected before plotting") raise Exception("Correlator must be projected before plotting")
if auto_gamma:
self.gamma_method()
if x_range is None: if x_range is None:
x_range = [0, self.T - 1] x_range = [0, self.T - 1]
@ -722,7 +729,6 @@ class Corr:
if logscale: if logscale:
ax1.set_yscale('log') ax1.set_yscale('log')
else: else:
# we generate ylim instead of using autoscaling.
if y_range is None: if y_range is None:
try: try:
y_min = min([(x[0].value - x[0].dvalue) for x in self.content[x_range[0]: x_range[1] + 1] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)]) y_min = min([(x[0].value - x[0].dvalue) for x in self.content[x_range[0]: x_range[1] + 1] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)])
@ -735,17 +741,21 @@ class Corr:
if comp: if comp:
if isinstance(comp, (Corr, list)): if isinstance(comp, (Corr, list)):
for corr in comp if isinstance(comp, list) else [comp]: for corr in comp if isinstance(comp, list) else [comp]:
if auto_gamma:
corr.gamma_method()
x, y, y_err = corr.plottable() x, y, y_err = corr.plottable()
plt.errorbar(x, y, y_err, label=corr.tag, mfc=plt.rcParams['axes.facecolor']) plt.errorbar(x, y, y_err, label=corr.tag, mfc=plt.rcParams['axes.facecolor'])
else: else:
raise Exception('comp must be a correlator or a list of correlators.') raise Exception("'comp' must be a correlator or a list of correlators.")
if plateau: if plateau:
if isinstance(plateau, Obs): if isinstance(plateau, Obs):
if auto_gamma:
plateau.gamma_method()
ax1.axhline(y=plateau.value, linewidth=2, color=plt.rcParams['text.color'], alpha=0.6, marker=',', ls='--', label=str(plateau)) ax1.axhline(y=plateau.value, linewidth=2, color=plt.rcParams['text.color'], alpha=0.6, marker=',', ls='--', label=str(plateau))
ax1.axhspan(plateau.value - plateau.dvalue, plateau.value + plateau.dvalue, alpha=0.25, color=plt.rcParams['text.color'], ls='-') ax1.axhspan(plateau.value - plateau.dvalue, plateau.value + plateau.dvalue, alpha=0.25, color=plt.rcParams['text.color'], ls='-')
else: else:
raise Exception('plateau must be an Obs') raise Exception("'plateau' must be an Obs")
if self.prange: if self.prange:
ax1.axvline(self.prange[0], 0, 1, ls='-', marker=',') ax1.axvline(self.prange[0], 0, 1, ls='-', marker=',')
ax1.axvline(self.prange[1], 0, 1, ls='-', marker=',') ax1.axvline(self.prange[1], 0, 1, ls='-', marker=',')
@ -770,7 +780,7 @@ class Corr:
if isinstance(save, str): if isinstance(save, str):
fig.savefig(save) fig.savefig(save)
else: else:
raise Exception("Safe has to be a string.") raise Exception("'save' has to be a string.")
return return