def z_hists(data, dz):
    from matplotlib.ticker import AutoMinorLocator, MultipleLocator

    x, y = [], []
    for k in dz:
        for t in data:
            xx, yy = data_hist(t, k)
            x.append(xx)
            y.append(yy)

    fig = plt.figure(figsize=(15, 8))
    axes = []
    for i in range(8):
        axes.append(fig.add_subplot(4, 2, i + 1))
        axes[i].hist(x[i][:-1], bins=x[i], weights=y[i])
        axes[i].set_xlim(0, 6)
        axes[i].xaxis.set_major_locator(MultipleLocator(1))
        axes[i].xaxis.set_minor_locator(AutoMinorLocator(2))

    axes[0].set_ylabel('N(z)')
    axes[2].set_ylabel('N(z)')
    axes[4].set_ylabel('N(z)')
    axes[6].set_ylabel('N(z)')
    axes[6].set_xlabel('z')
    axes[7].set_xlabel('z')

    axes[0].set_title('Z_MIN_CHI2')
    axes[1].set_title('Z_MED_PDZ')

    fig.tight_layout()
    plt.show()
def structures_old(data, dz, kind, save=False, path=None):
    xb, y = data_hist(data, dz, bi='edges')
    x = [xb[i] + dz / 2 for i in range(len(xb) - 1)]
    x, y = np.array(x), np.array(y)

    par = ap.fast(x, y, kind)[0]
    delta = (y - y_app(xb, dz, par, kind)) / y_app(xb, dz, par, kind)
    sigma = 1 / y_app(xb, dz, par, kind)

    number, *d = my_main_old(x, delta, sigma)
    table_dict = {
        'n': d[0],
        'z start': d[1],
        'st err com': d[2],
        'st err pro': d[3],
        'z finish': d[4],
        'fin err com': d[5],
        'fin err pro': d[6],
        'z middle': d[7],
        'r comoving': d[8],
        'r proper': d[9],
        'sigma fluct': d[10],  # несмещённая дисперсия
        'sigma fluct err': d[11],
        'sigma Poisson': d[12],
        'sigma obs': d[13]
    }

    table = pd.DataFrame(table_dict, index=number)
    table.index.name = 'j'

    if save:
        if path is not None:
            filename = path + 'dz={:.3f} kind {}.csv'.format(dz, kind)
        else:
            filename = 'dz={:.3f} kind {}.csv'.format(dz, kind)
        table.to_csv(filename)
    else:
        pd.set_option('display.max_rows', 500)
        pd.set_option('display.max_columns', 500)
        pd.set_option('display.width', 1000)
        print(table)
def fluct_table(data, dz, kind, save=False, path=None):
    xb, y = data_hist(data, dz, bi='edges')
    x = [xb[i] + dz / 2 for i in range(len(xb) - 1)]
    x, y = np.array(x), np.array(y)

    par = ap.fast(x, y, kind)[0]
    delta = (y - y_app(xb, dz, par, kind)) / y_app(xb, dz, par, kind)
    sigma = 5 / np.sqrt(y_app(xb, dz, par, kind))

    r = [
        di.r_comoving(xb[i]) - di.r_comoving(xb[i - 1])
        for i in range(1, len(xb))
    ]
    d_l = [
        di.r_proper(xb[i]) - di.r_proper(xb[i - 1]) for i in range(1, len(xb))
    ]

    table_dict = {
        'z': x,
        'R': r,
        'd_L': d_l,
        'delta': delta,
        '5 sigma Poisson': sigma
    }

    table = pd.DataFrame(table_dict)
    table.index.name = 'i'

    if save:
        if path is not None:
            filename = path + 'dz={:.3f} kind {}.csv'.format(dz, kind)
        else:
            filename = 'dz={:.3f} kind {}.csv'.format(dz, kind)
        table.to_csv(filename)
    else:
        pd.set_option('display.max_rows', 500)
        pd.set_option('display.max_columns', 500)
        pd.set_option('display.width', 1000)
        print(table)
def structures(data, dz, kind, save=False, path=None):
    xb, y = data_hist(data, dz, bi='edges')
    x = [xb[i] + dz / 2 for i in range(len(xb) - 1)]
    x, y = np.array(x), np.array(y)

    par = ap.fast(x, y, kind)[0]
    delta = (y - y_app(xb, dz, par, kind)) / y_app(xb, dz, par, kind)
    integrals = y_app(xb, dz, par, kind)

    j, *d = my_main(x, delta, integrals)
    t = {
        'n': d[0] + [''],
        'z middle': np.around(d[3] + [sum(d[3]) / j[-1]], 2),
        'z err': np.around(d[4] + [sum(d[4]) / j[-1]], 2),
        'r comoving': d[5],
        'st err com': d[6],
        'fin err com': d[7],
        'sigma Poisson': d[8] + [sum(d[8]) / j[-1]],
        'sigma obs': d[9] + [sum(d[9]) / j[-1]],
        'sigma obs err': d[10],
        'sigma dm': d[11] + [sum(d[11]) / j[-1]],
        'b dm': d[12],
        'sigma b dm': [],
        'sigma pl': d[13] + [sum(d[13]) / j[-1]],
        'b pl': d[14],
        'sigma b pl': []
    }

    zero_count = 0
    for i in range(j[-1]):
        if t['b dm'][i] == 0:
            zero_count += 1
    t['b dm'] = t['b dm'] + [sum(t['b dm']) / (j[-1] - zero_count)]
    t['b pl'] = t['b pl'] + [sum(t['b pl']) / (j[-1] - zero_count)]

    r_mean = sum(t['r comoving']) / j[-1]
    r_sigma = 0
    sigma_sigma_obs = 0
    sigma_sigma_b_dm = 0
    sigma_sigma_b_pl = 0
    for i in range(j[-1]):
        r_sigma += (t['r comoving'][i] - r_mean)**2
        sigma_sigma_obs += (t['sigma obs'][i] - t['sigma obs'][-1])**2
        sigma_sigma_b_dm += (t['b dm'][i] - t['b dm'][-1])**2
        sigma_sigma_b_pl += (t['b pl'][i] - t['b pl'][-1])**2
        t['sigma b dm'].append(t['b dm'][i] * t['sigma obs err'][i] /
                               t['sigma obs'][i])
        t['sigma b pl'].append(t['b pl'][i] * t['sigma obs err'][i] /
                               t['sigma obs'][i])

    r_sigma /= j[-1] - 1
    sigma_sigma_obs /= j[-1] - 1
    sigma_sigma_b_dm /= j[-1] - 1
    sigma_sigma_b_pl /= j[-1] - 1

    r_st_err_mean = np.sqrt(
        (sum(t['st err com'])**2 / (j[-1] - 1) + r_sigma) /
        j[-1])  # the calculating for standard error of the means
    r_fin_err_mean = np.sqrt(
        (sum(t['fin err com'])**2 / (j[-1] - 1) + r_sigma) /
        j[-1])  # the calculating for standard error of the means
    sigma_obs_err_mean = np.sqrt(
        (t['sigma Poisson'][-1]**2 + sigma_sigma_obs) /
        j[-1])  # the calculating for standard error of the means

    # r_st_err_mean = np.sqrt((sum(t['st err com']) / j[-1]) ** 2 + r_sigma) / np.sqrt(j[-1])       # the calculating for standard error of the means
    # r_fin_err_mean = np.sqrt((sum(t['fin err com']) / j[-1]) ** 2 + r_sigma) / np.sqrt(j[-1])     # the calculating for standard error of the means
    # sigma_obs_err_mean = np.sqrt(t['sigma Poisson'][-1] ** 2 + sigma_sigma_obs) / np.sqrt(j[-1])  # the calculating for standard error of the means

    sigma_sigma_b_dm /= j[
        -1]  # the calculating for standard error of the means
    sigma_sigma_b_pl /= j[
        -1]  # the calculating for standard error of the means

    t['r comoving'] = [int(i) for i in t['r comoving'] + [r_mean]]
    t['st err com'] = [int(i) for i in t['st err com'] + [r_st_err_mean]]
    t['fin err com'] = [int(i) for i in t['fin err com'] + [r_fin_err_mean]]
    t['sigma obs err'] = t['sigma obs err'] + [sigma_obs_err_mean]
    t['b dm'] = np.around(t['b dm'], 2)
    t['sigma b dm'] = np.around(t['sigma b dm'] + [np.sqrt(sigma_sigma_b_dm)],
                                2)
    t['b pl'] = np.around(t['b pl'], 2)
    t['sigma b pl'] = np.around(t['sigma b pl'] + [np.sqrt(sigma_sigma_b_pl)],
                                2)

    j += ['means:']
    table = pd.DataFrame(t, index=j)
    table.index.name = 'j'

    if save:
        if path is not None:
            filename = path + 'dz={:.3f} kind {}.csv'.format(dz, kind)
        else:
            filename = 'dz={:.3f} kind {}.csv'.format(dz, kind)
        table.to_csv(filename)
    else:
        pd.set_option('display.max_rows', 500)
        pd.set_option('display.max_columns', 500)
        pd.set_option('display.width', 1000)
        print(table)
Beispiel #5
0
def z_c_graph(data, func, dz, w, save=False, path=None):
    print('dz={}, w>{}'.format(str(dz), str(w)))

    x, y = data_hist(data, dz, bi='center')

    par1, s1 = fast(x, y, 1)
    par2, s2 = fast(x, y, 2)
    par3, s3 = fast(x, y, 3)

    a1, b1, c1 = par1
    a2, b2, c2 = par2
    a3, b3, c3 = par3

    p = ['{:.2f}'.format(k) for k in [a1, b1, a2, b2, a3, b3]]
    a1, b1, a2, b2, a3, b3 = p
    p = ['{:.0f}'.format(k) for k in [c1, c2, c3]]
    c1, c2, c3 = p

    x0 = np.linspace(x[0], x[-1], 1000)

    fig, ax = plt.subplots(figsize=(12.8, 7.2))
    ax.scatter(x, y, s=10, c=[[1, 0, 1] for i in x])
    ax.plot(x, y)

    label1 = r'$\mathrm{' + c1 + 'x^{' + a1 + r'}e^{\left(-\frac{x}{' + '1' + r'}\right)^{' + b1 + '}}}$'
    label1 += ', ' + '%.3e' % s1
    ax.plot(x0,
            f(x0, par1, 1),
            color='orange',
            linestyle='--',
            linewidth=0.8,
            label=label1)

    label2 = r'$\mathrm{' + str(
        int(c2)
    ) + 'x^{' + a2 + r'}e^{\left(-\frac{x}{' + '3' + r'}\right)^{' + b2 + '}}}$'
    label2 += ', ' + '%.3e' % s2
    ax.plot(x0,
            f(x0, par2, 2),
            color='limegreen',
            linestyle='--',
            linewidth=0.8,
            label=label2)

    label3 = r'$\mathrm{' + c3 + 'x^{' + a3 + r'}e^{\left(-\frac{x}{' + '6' + r'}\right)^{' + b3 + '}}}$'
    label3 += ', ' + '%.3e' % s3
    ax.plot(x0,
            f(x0, par3, 3),
            color='orangered',
            linestyle='--',
            linewidth=0.8,
            label=label3)

    ax.set_xlabel('z', fontsize='x-large')
    ax.set_ylabel('N(z)', fontsize='x-large')

    ax.set_xlim(0)
    ax.set_ylim(0)

    if w == -100:
        plt.title('Approximations for {} with dz={}, all w, N={:d}'.format(
            func.upper(), str(dz), sum(y)),
                  fontsize='x-large')
    else:
        plt.title('Approximations for {} with dz={}, w>{}, N={:d}'.format(
            func.upper(), str(dz), str(w), sum(y)),
                  fontsize='x-large')

    ax.legend(fontsize='x-large')
    ax.tick_params(labelsize='x-large')

    if save:
        if path is not None:
            filename = path + 'dz={:.3f}.png'.format(dz)
        else:
            filename = 'dz={:.3f}.png'.format(dz)
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()
Beispiel #6
0
def z_c_fluct(data, func, dz, w, save=False, path=None):
    from matplotlib.ticker import FixedLocator
    from scipy import integrate

    def y_app(bins, par, kind):
        yapp = []
        for i in range(1, len(bins)):
            yapp.append(
                integrate.quad(f, bins[i - 1], bins[i], args=(par, kind))[0] /
                dz)
        return np.array(yapp)

    print('dz={}, w>{}'.format(dz, w))

    xb, y = data_hist(data, dz, bi='edges')
    x = [xb[i] + dz / 2 for i in range(len(xb) - 1)]
    x, y = np.array(x), np.array(y)

    par1, s1 = fast(x, y, 1)
    par2, s2 = fast(x, y, 2)
    par3, s3 = fast(x, y, 3)

    a1, b1, c1 = par1
    a2, b2, c2 = par2
    a3, b3, c3 = par3

    p = ['{:.2f}'.format(k) for k in [a1, b1, a2, b2, a3, b3]]
    a1, b1, a2, b2, a3, b3 = p
    p = ['{:.0f}'.format(k) for k in [c1, c2, c3]]
    c1, c2, c3 = p

    ig, ax = plt.subplots(figsize=(12.8, 7.2))

    label1 = r'$\mathrm{' + c1 + 'x^{' + a1 + r'}e^{\left(-\frac{x}{' + '1' + r'}\right)^{' + b1 + '}}}$'
    label1 += ', ' + '%.3e' % s1
    ax.plot(x, (y - y_app(xb, par1, 1)) / y_app(xb, par1, 1),
            color='orange',
            linewidth=0.9,
            label=label1)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par1, 1)),
            color='orange',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par1, 1)),
            color='orange',
            linestyle='--',
            linewidth=0.5)

    label2 = r'$\mathrm{' + c2 + 'x^{' + a2 + r'}e^{\left(-\frac{x}{' + '3' + r'}\right)^{' + b2 + '}}}$'
    label2 += ', ' + '%.3e' % s2
    ax.plot(x, (y - y_app(xb, par2, 2)) / y_app(xb, par2, 2),
            color='limegreen',
            linewidth=0.9,
            label=label2)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par2, 2)),
            color='limegreen',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par2, 2)),
            color='limegreen',
            linestyle='--',
            linewidth=0.5)

    label3 = r'$\mathrm{' + c3 + 'x^{' + a3 + r'}e^{\left(-\frac{x}{' + '6' + r'}\right)^{' + b3 + '}}}$'
    label3 += ', ' + '%.3e' % s3
    ax.plot(x, (y - y_app(xb, par3, 3)) / y_app(xb, par3, 3),
            color='orangered',
            linewidth=0.9,
            label=label3)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par3, 3)),
            color='orangered',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par3, 3)),
            color='orangered',
            linestyle='--',
            linewidth=0.5)

    ax.tick_params(axis='x', direction='inout')
    ax.xaxis.set_major_locator(FixedLocator([1, 2, 3, 4, 5, 6]))
    ax.tick_params(labelsize='x-large')

    ax.spines['bottom'].set_position(('data', 0.0))
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)

    ax.set_xlabel('z', fontsize='x-large')
    ax.xaxis.set_label_coords(1.01, 0.516)
    ax.set_ylabel(
        r'$\mathrm{\delta=\frac{\Delta N_{obs} - \Delta N_{approx}}{\Delta N_{approx}}}$',
        fontsize='xx-large')

    ax.set_xlim(0, 6.1)

    if w != 'all w' and float(w) > 0.8:
        ax.set_ylim(-1, 1)
    else:
        limits = plt.axis()
        ylim = max(abs(limits[2]), abs(limits[3]))
        ax.set_ylim(-ylim, ylim)

    if w == -100:
        plt.title('Fluctuations for {} with dz={}, all w, N={:d}'.format(
            func.upper(), dz, sum(y)),
                  fontsize='x-large')
    else:
        plt.title('Fluctuations for {} with dz={}, w>{}, N={:d}'.format(
            func.upper(), dz, w, sum(y)),
                  fontsize='x-large')

    ax.legend(fontsize='x-large')

    if save:
        if path is not None:
            filename = path + 'dz={:.3f}.png'.format(dz)
        else:
            filename = 'dz={:.3f}.png'.format(dz)
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()
def app_graph_r(data, dr, w, save=False, path=None):
    print(f'dz={dr}, w>{w}')

    x, y = data_hist(data, dr, bi='center')

    # par1, s1 = ap.fast(x, y, 1)
    # par2, s2 = ap.fast(x, y, 2)
    par3, s3 = ap.fast(x, y, 3)

    # a1, b1, c1 = par1
    # a2, b2, z2, c2 = par2
    a3, b3, d3, c3 = par3

    # p = ['{:.2f}'.format(k) for k in [a3, b3]]
    # a3, b3 = p
    # d3 = f'{d3:.0e}'
    # c3 = f'{c3:.0e}'

    x0 = np.linspace(x[0], x[-1], 1000)

    fig, ax = plt.subplots(figsize=(12.8 * frac, 7.2 * frac))
    ax.scatter(x, y, s=10, c=[[1, 0, 1] for i in x])
    ax.plot(x, y)

    # label1 = r'$\mathrm{' + str(int(c1)) + 'z^{' + a1 + '}e^{-' + b1 + 'z}}$'
    # label1 += ', ' + '%.3e' % s1
    # ax.plot(x0, ap.f(x0, par1, 1), color='orange', linestyle='--', linewidth=0.8, label=label1)

    # label2 = r'$\mathrm{' + str(int(c2)) + 'z^{' + a2 + r'}e^{\left(-\frac{z}{' + z2 + r'}\right)^{' + b2 + '}}}$'
    # label2 += ', ' + '%.3e' % s2
    # ax.plot(x0, ap.f(x0, par2, 2), color='limegreen', linestyle='--', linewidth=0.8, label=label2)

    # label3 = r'$\mathrm{' + c3 + r'\left(\frac{R^{' + a3 + '}+R^{' + a3 + r'\cdot' + b3 + '}}{R^{' + b3 + \
    #          '}+' + d3 + r'}\right)}$'
    # label3 += ', ' + '%.3e' % s3
    ax.plot(x0,
            ap.f(x0, par3, 3),
            color='orangered',
            linestyle='--',
            linewidth=0.8)

    ax.set_xlabel('R', fontsize='x-large')
    ax.set_ylabel(r'$\mathrm{\Delta N(R,\Delta R)}$', fontsize='x-large')

    ax.set_xlim(0)
    ax.set_ylim(0)

    if w == -100:
        plt.title('Approximations with dR={}, all w, N={:d}'.format(
            str(dr), sum(y)),
                  fontsize='x-large')
    else:
        plt.title('Approximations with dR={}, w>{}, N={:d}'.format(
            str(dr), str(w), sum(y)),
                  fontsize='x-large')

    # ax.legend(fontsize='x-large')

    # if the legend is superimposed on the graph
    # ax.legend(fontsize='x-large', loc='lower left', bbox_to_anchor=(0.05, 0))

    ax.tick_params(labelsize='x-large')

    if save:
        if path is not None:
            filename = path + 'dR={:.3f}.png'.format(dr)
        else:
            filename = 'dR={:.3f}.png'.format(dr)
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()
def r_hists(dr, w, save=False, path=None):
    from data_processing import distance
    from data_processing import z_final
    from distance import r_comoving

    print('dr=' + str(dr))

    x = []
    y = []
    for wi in w:
        data = distance(w=wi)
        # data = [r_comoving(i) for i in z_med_pdz(w=wi)]
        xx, yy = data_hist(data, dr)
        x.append(xx)
        y.append(yy)

    fig, ax = plt.subplots(figsize=(12.8 * frac, 7.2 * frac))

    if w[0] == -100:
        label = 'all w, N={:d}'.format(sum(y[0]))
        ax.hist(x[0][:-1],
                bins=x[0],
                weights=y[0],
                histtype='step',
                label=label)
    else:
        label = 'w>{}, N={:d}'.format(str(w[0]), sum(y[0]))
        ax.hist(x[0][:-1],
                bins=x[0],
                weights=y[0],
                histtype='stepfilled',
                alpha=0.9,
                label=label)

    for i in range(1, len(w)):
        label = 'w>{}, N={:d}'.format(str(w[i]), sum(y[i]))
        if i == 4:
            ax.hist(x[i][:-1],
                    bins=x[i],
                    weights=y[i],
                    histtype='stepfilled',
                    color='#FFD94A',
                    alpha=0.9,
                    label=label)
        else:
            ax.hist(x[i][:-1],
                    bins=x[i],
                    weights=y[i],
                    histtype='stepfilled',
                    alpha=0.9,
                    label=label)

    ax.set_xlabel('r', fontsize='x-large')
    ax.set_ylabel(r'$\mathrm{\Delta N(R,\Delta R)}$', fontsize='x-large')

    ax.set_xlim(0, max(x[0]))
    ax.set_ylim(0)

    ax.legend(fontsize='x-large')
    ax.tick_params(labelsize='x-large')
    plt.title(r'Histograms with $\mathrm{\Delta R=' + str(dr) + '}$',
              fontsize='x-large')

    if save:
        if path is not None:
            filename = f'{path}dr={dr}.png'
        else:
            filename = f'dr={dr}.png'
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()
def w_hists(dz, w, integral=False, save=False, path=None, file=None):
    from data_processing import z_final
    # from data_processing import z_med_pdz

    print('dz={}'.format(dz))

    x = []
    y = []
    y_sum = []
    for wi in w:
        data = z_final(w=wi, file=file)
        # data = z_med_pdz(w=wi)
        xx, yy = data_hist(data, dz)

        if integral:
            yyy = [yy[0]]
            for i in range(1, len(yy)):
                yyy.append(yyy[-1] + yy[i])

            y.append(yyy)
            y_sum.append(yyy[-1])
        else:
            y.append(yy)
            y_sum.append(sum(yy))

        x.append(xx)

    fig, ax = plt.subplots(figsize=(12.8 * frac, 7.2 * frac))

    if w[0] == -100:
        label = 'all w, N={:d}'.format(y_sum[0])
        ax.hist(x[0][:-1],
                bins=x[0],
                weights=y[0],
                histtype='step',
                label=label)
    else:
        label = 'w>{}, N={:d}'.format(str(w[0]), y_sum[0])
        ax.hist(x[0][:-1],
                bins=x[0],
                weights=y[0],
                histtype='stepfilled',
                alpha=0.9,
                label=label)

    for i in range(1, len(w)):
        label = 'w>{}, N={:d}'.format(str(w[i]), y_sum[i])
        if i == 4:
            ax.hist(x[i][:-1],
                    bins=x[i],
                    weights=y[i],
                    histtype='stepfilled',
                    color='#FFD94A',
                    alpha=0.9,
                    label=label)
        else:
            ax.hist(x[i][:-1],
                    bins=x[i],
                    weights=y[i],
                    histtype='stepfilled',
                    alpha=0.9,
                    label=label)

    ax.set_xlabel('z', fontsize='x-large')
    ax.set_ylabel(r'$\mathrm{\Delta N(z,\Delta z)}$', fontsize='x-large')

    ax.set_xlim(0, max(x[0]))
    ax.set_ylim(0)

    ax.legend(fontsize='x-large')
    ax.tick_params(labelsize='x-large')
    plt.title(r'Histograms with $\mathrm{\Delta z=' + str(dz) + '}$',
              fontsize='x-large')

    if save:
        if path is not None:
            filename = f'{path}dz={dz:.3f}.png'
        else:
            filename = f'dz={dz:.3f}.png'
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()
def fluct_graph(data, func, dz, w, save=False, path=None):
    from matplotlib.ticker import FixedLocator
    from scipy import integrate

    def y_app(bins, par, kind):
        yapp = []
        for i in range(1, len(bins)):
            yapp.append(
                integrate.quad(ap.f, bins[i - 1], bins[i], args=(par, kind))[0]
                / dz)
        return np.array(yapp)

    print(f'dz={dz}, w>{w}')

    xb, y = data_hist(data, dz, bi='edges')
    x = [xb[i] + dz / 2 for i in range(len(xb) - 1)]
    x, y = np.array(x), np.array(y)

    par1, s1 = ap.fast(x, y, 1)
    par2, s2 = ap.fast(x, y, 2)
    par3, s3 = ap.fast(x, y, 3)

    a1, b1, c1 = par1
    a2, b2, z2, c2 = par2
    a3, b3, d3, c3 = par3

    p = ['{:.2f}'.format(k) for k in [a1, b1, a2, b2, z2, a3, b3, d3]]
    a1, b1, a2, b2, z2, a3, b3, d3 = p
    p = ['{:.0f}'.format(k) for k in [c1, c2, c3]]
    c1, c2, c3 = p

    ig, ax = plt.subplots(figsize=(12.8 * frac, 7.2 * frac))

    # label_sigma = r'$5\sigma$'

    label1 = r'$\mathrm{' + c1 + 'z^{' + a1 + '}e^{-' + b1 + 'z}}$'
    label1 += ', ' + '%.3e' % s1
    ax.plot(x, (y - y_app(xb, par1, 1)) / y_app(xb, par1, 1),
            color='orange',
            linewidth=0.9,
            label=label1)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par1, 1)),
            color='orange',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par1, 1)),
            color='orange',
            linestyle='--',
            linewidth=0.5)

    label2 = r'$\mathrm{' + c2 + 'z^{' + a2 + r'}e^{\left(-\frac{z}{' + z2 + r'}\right)^{' + b2 + '}}}$'
    label2 += ', ' + '%.3e' % s2
    ax.plot(x, (y - y_app(xb, par2, 2)) / y_app(xb, par2, 2),
            color='limegreen',
            linewidth=0.9,
            label=label2)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par2, 2)),
            color='limegreen',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par2, 2)),
            color='limegreen',
            linestyle='--',
            linewidth=0.5)

    label3 = r'$\mathrm{' + c3 + r'\left(\frac{z^{' + a3 + '}+z^{' + a3 + r'\cdot' + b3 + '}}{z^{' + b3 + '}+' + d3 + \
             r'}\right)}$'
    label3 += ', ' + '%.3e' % s3
    ax.plot(x, (y - y_app(xb, par3, 3)) / y_app(xb, par3, 3),
            color='orangered',
            linewidth=0.9,
            label=label3)
    ax.plot(x,
            5 / np.sqrt(y_app(xb, par3, 3)),
            color='orangered',
            linestyle='--',
            linewidth=0.5)
    ax.plot(x,
            -5 / np.sqrt(y_app(xb, par3, 3)),
            color='orangered',
            linestyle='--',
            linewidth=0.5)

    ax.tick_params(axis='x', direction='inout')
    ax.xaxis.set_major_locator(FixedLocator([1, 2, 3, 4, 5, 6]))
    ax.tick_params(labelsize='x-large')

    ax.spines['bottom'].set_position(('data', 0.0))
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)

    ax.set_xlabel('z', fontsize='x-large')
    ax.xaxis.set_label_coords(1.01, 0.516)

    # if the name of the x axis is superimposed on numbers
    if frac < 1:
        ax.set_ylabel(
            r'$\mathrm{\delta=\frac{\Delta N_{obs} - \Delta N_{approx}}{\Delta N_{approx}}}$',
            fontsize='xx-large',
            labelpad=-10)
    else:
        ax.set_ylabel(
            r'$\mathrm{\delta=\frac{\Delta N_{obs} - \Delta N_{approx}}{\Delta N_{approx}}}$',
            fontsize='xx-large')

    ax.set_xlim(0)

    if float(w) > 0.8:
        ax.set_ylim(-1.05, 1.05)
    else:
        limits = plt.axis()
        ylim = max(abs(limits[2]), abs(limits[3]))
        ax.set_ylim(-ylim, ylim)

    if w == -100:
        plt.title('Fluctuations with dz={}, all w, N={:d}'.format(dz, sum(y)),
                  fontsize='x-large')
    else:
        plt.title('Fluctuations with dz={}, w>{}, N={:d}'.format(
            dz, w, sum(y)),
                  fontsize='x-large')

    ax.legend(fontsize='x-large')

    # if the legend is superimposed on the graph
    # ax.legend(fontsize='x-large', loc='lower left', bbox_to_anchor=(0.02, 0))
    # ax.set_ylim(-1.6, 1.6)

    if save:
        if path is not None:
            filename = path + 'dz={:.3f}.png'.format(dz)
        else:
            filename = 'dz={:.3f}.png'.format(dz)
        plt.savefig(filename, dpi=150)
    else:
        plt.show()

    plt.close()