Examples updated, minor bug fixes

This commit is contained in:
Fabian Joswig 2021-10-11 18:31:02 +01:00
parent e7ea0df660
commit 1d74e8c4f4
12 changed files with 1886 additions and 1717 deletions

View file

@ -358,7 +358,7 @@ class Corr:
return
# Plotting routine for correlator
def show(self, x_range=None, comp=None, logscale=False, plateau=None, fit_res=None, save=None, ylabel=None):
def show(self, x_range=None, comp=None, y_range=None, logscale=False, plateau=None, fit_res=None, save=None, ylabel=None):
"""Plots the correlator, uses tag as label if available.
Parameters
@ -371,7 +371,7 @@ class Corr:
if self.N!=1:
raise Exception("Correlator must be projected before plotting")
if x_range is None:
x_range=[0, self.T]
x_range = [0, self.T]
fig = plt.figure()
ax1 = fig.add_subplot(111)
@ -382,12 +382,15 @@ class Corr:
ax1.set_yscale('log')
else:
# we generate ylim instead of using autoscaling.
try:
y_min=min([(x[0].value - x[0].dvalue) for x in self.content[x_range[0]:x_range[1]] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)])
y_max=max([(x[0].value + x[0].dvalue) for x in self.content[x_range[0]:x_range[1]] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)])
ax1.set_ylim([y_min - 0.1 * (y_max - y_min), y_max + 0.1 * (y_max - y_min)])
except:
pass
if y_range is None:
try:
y_min=min([(x[0].value - x[0].dvalue) for x in self.content[x_range[0]:x_range[1]] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)])
y_max=max([(x[0].value + x[0].dvalue) for x in self.content[x_range[0]:x_range[1]] if (x is not None) and x[0].dvalue < 2 * np.abs(x[0].value)])
ax1.set_ylim([y_min - 0.1 * (y_max - y_min), y_max + 0.1 * (y_max - y_min)])
except:
pass
else:
ax1.set_ylim(y_range)
if comp:
if isinstance(comp, Corr) or isinstance(comp, list):
for corr in comp if isinstance(comp, list) else [comp]:

View file

@ -575,7 +575,7 @@ def residual_plot(x, y, func, fit_res):
gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1], wspace=0.0, hspace=0.0)
ax0 = plt.subplot(gs[0])
ax0.errorbar(x, [o.value for o in y], yerr=[o.dvalue for o in y], ls='none', fmt='o', capsize=3, markersize=5, label='Data')
ax0.plot(x_samples, func([o.value for o in fit_res], x_samples), label='Fit', zorder=10)
ax0.plot(x_samples, func([o.value for o in fit_res], x_samples), label='Fit', zorder=10, ls='-', ms=0)
ax0.set_xticklabels([])
ax0.set_xlim([xstart, xstop])
ax0.set_xticklabels([])