def plotFitData(plotTitle, xTitle, yTitle, viewGrid, viewParameters, viewResiduals):
    global x
    global y
    global y_err
    global ERR
    global numberOfDataPoints
    global function
    global numberOfParameters
    global fitParameters
    global fitErrors
    global chiSquared
    global redChiSquared
    global redChiSquaredLimits
    figure2 = plt.figure()
    if (viewResiduals and viewParameters):
        gs = gridspec.GridSpec(2, 2, height_ratios=[3, 1], width_ratios=[4, 1])
        axes2 = figure2.add_subplot(gs[(0, 0)])
        axes3 = figure2.add_subplot(gs[(1, 0)])
        axes4 = figure2.add_subplot(gs[(0, 1)])
    elif (viewResiduals and (not viewParameters)):
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        axes2 = figure2.add_subplot(gs[0])
        axes3 = figure2.add_subplot(gs[1])
    elif ((not viewResiduals) and viewParameters):
        gs = gridspec.GridSpec(1, 2, width_ratios=[4, 1])
        axes2 = figure2.add_subplot(gs[0])
        axes4 = figure2.add_subplot(gs[1])
    else:
        axes2 = figure2.add_subplot(111)
    axes2.set_title(plotTitle, fontsize='x-large')
    axes2.set_xlabel(xTitle, fontsize='large')
    axes2.set_ylabel(yTitle, fontsize='large')
    if viewGrid:
        axes2.minorticks_on()
        axes2.set_axisbelow(True)
        axes2.grid(b=True, which='major', alpha=0.5)
        axes2.grid(b=True, which='minor', alpha=0.2)
        if viewResiduals:
            axes3.minorticks_on()
            axes3.set_axisbelow(True)
            axes3.grid(b=True, which='major', alpha=0.5)
            axes3.grid(b=True, which='minor', alpha=0.2)
    if ERR:
        axes2.errorbar(x, y, y_err, fmt='.', color='midnightblue', ecolor='royalblue', capsize=2, zorder=1, label='Data')
    else:
        axes2.scatter(x, y, color='midnightblue', label='Data')
    xx = np.linspace(min(x), max(x), 1000)
    yy = functions[function].func(xx, *fitParameters)
    axes2.plot(xx, yy, color='darkorange', zorder=2, label='Fit function')
    if viewResiduals:
        residuals = (functions[function].func(x, *fitParameters) - y)
        axes3.axhline(0, color='darkorange', zorder=2)
        if (ERR == True):
            axes3.errorbar(x, residuals, y_err, fmt='.', color='midnightblue', ecolor='royalblue', capsize=2, zorder=1)
        else:
            axes3.scatter(x, residuals, color='midnightblue')
    axes2.legend(markerscale=2, fontsize='large')
    if viewParameters:
        axes4.set_axis_off()
        parametersStr = []
        parametersStr.append('$\\bf{Function:}$')
        parametersStr.append(functions[function].name)
        parametersStr.append(functions[function].rawFuncStr)
        parametersStr.append('')
        parametersStr.append('$\\bf{Fitting\\/parameters:}$')
        for i in range(numberOfParameters):
            parametersStr.append((functions[function].rawParametersStr[i] + ' = {0:.5e} $\\pm$ {1:.5e}'.format(fitParameters[i], fitErrors[i])))
        parametersStr.append('')
        parametersStr.append('$\\bf{Other\\/fitting\\/data:}$')
        parametersStr.append('Number of data points = {0}'.format(numberOfDataPoints))
        parametersStr.append('Number of parameters  = {0}'.format(numberOfParameters))
        parametersStr.append('$\\chi^2$ = {0:.5e}'.format(chiSquared))
        parametersStr.append('$\\chi_r^2$ = {0:.5e}'.format(redChiSquared))
        parametersStr.append('Acceptable range of $\\chi_r^2$ = ({0:.2f},{1:.2f})'.format(redChiSquaredLimits[0], redChiSquaredLimits[1]))
        if (not ERR):
            parametersStr.append('')
            parametersStr.append('$\\bf{Note}$: Errors and chi-squared estimates')
            parametersStr.append('here dont mean much since no errors')
            parametersStr.append('along y-axis are present!')
        parametersStr = '\n'.join(parametersStr)
        axes4.text((- 0.35), 1.0, parametersStr, bbox=dict(boxstyle='square', fc='lemonchiffon', ec='darkorange', pad=0.5), va='top', ha='left', fontsize='large', linespacing=1.3)
    figure2.show()
def plotFitData(plotTitle, xTitle, yTitle, viewGrid, viewParameters, viewResiduals):
    global x
    global y
    global y_err
    global ERR
    global numberOfDataPoints
    global function
    global numberOfParameters
    global fitParameters
    global fitErrors
    global chiSquared
    global redChiSquared
    global redChiSquaredLimits
    figure2 = plt.figure()
    if (viewResiduals and viewParameters):
        gs = gridspec.GridSpec(2, 2, height_ratios=[3, 1], width_ratios=[4, 1])
        axes2 = figure2.add_subplot(gs[(0, 0)])
        axes3 = figure2.add_subplot(gs[(1, 0)])
        axes4 = figure2.add_subplot(gs[(0, 1)])
    elif (viewResiduals and (not viewParameters)):
        gs = gridspec.GridSpec(2, 1, height_ratios=[3, 1])
        axes2 = figure2.add_subplot(gs[0])
        axes3 = figure2.add_subplot(gs[1])
    elif ((not viewResiduals) and viewParameters):
        gs = gridspec.GridSpec(1, 2, width_ratios=[4, 1])
        axes2 = figure2.add_subplot(gs[0])
        axes4 = figure2.add_subplot(gs[1])
    else:
        axes2 = figure2.add_subplot(111)
    axes2.set_title(plotTitle, fontsize='x-large')
    axes2.set_xlabel(xTitle, fontsize='large')
    axes2.set_ylabel(yTitle, fontsize='large')
    if viewGrid:
        axes2.minorticks_on()
        axes2.set_axisbelow(True)
        axes2.grid(b=True, which='major', alpha=0.5)
        axes2.grid(b=True, which='minor', alpha=0.2)
        if viewResiduals:
            axes3.minorticks_on()
            axes3.set_axisbelow(True)
            axes3.grid(b=True, which='major', alpha=0.5)
            axes3.grid(b=True, which='minor', alpha=0.2)
    if ERR:
        axes2.errorbar(x, y, y_err, fmt='.', color='midnightblue', ecolor='royalblue', capsize=2, zorder=1, label='Data')
    else:
        axes2.scatter(x, y, color='midnightblue', label='Data')
    xx = np.linspace(min(x), max(x), 1000)
    yy = functions[function].func(xx, *fitParameters)
    axes2.plot(xx, yy, color='darkorange', zorder=2, label='Fit function')
    if viewResiduals:
        residuals = (functions[function].func(x, *fitParameters) - y)
        axes3.axhline(0, color='darkorange', zorder=2)
        if (ERR == True):
            axes3.errorbar(x, residuals, y_err, fmt='.', color='midnightblue', ecolor='royalblue', capsize=2, zorder=1)
        else:
            axes3.scatter(x, residuals, color='midnightblue')
    axes2.legend(markerscale=2, fontsize='large')
    if viewParameters:
        axes4.set_axis_off()
        parametersStr = []
        parametersStr.append('$\\bf{Function:}$')
        parametersStr.append(functions[function].name)
        parametersStr.append(functions[function].rawFuncStr)
        parametersStr.append()
        parametersStr.append('$\\bf{Fitting\\/parameters:}$')
        for i in range(numberOfParameters):
            parametersStr.append((functions[function].rawParametersStr[i] + ' = {0:.5e} $\\pm$ {1:.5e}'.format(fitParameters[i], fitErrors[i])))
        parametersStr.append()
        parametersStr.append('$\\bf{Other\\/fitting\\/data:}$')
        parametersStr.append('Number of data points = {0}'.format(numberOfDataPoints))
        parametersStr.append('Number of parameters  = {0}'.format(numberOfParameters))
        parametersStr.append('$\\chi^2$ = {0:.5e}'.format(chiSquared))
        parametersStr.append('$\\chi_r^2$ = {0:.5e}'.format(redChiSquared))
        parametersStr.append('Acceptable range of $\\chi_r^2$ = ({0:.2f},{1:.2f})'.format(redChiSquaredLimits[0], redChiSquaredLimits[1]))
        if (not ERR):
            parametersStr.append()
            parametersStr.append('$\\bf{Note}$: Errors and chi-squared estimates')
            parametersStr.append('here dont mean much since no errors')
            parametersStr.append('along y-axis are present!')
        parametersStr = '\n'.join(parametersStr)
        axes4.text((- 0.35), 1.0, parametersStr, bbox=dict(boxstyle='square', fc='lemonchiffon', ec='darkorange', pad=0.5), va='top', ha='left', fontsize='large', linespacing=1.3)
    figure2.show()