Ejemplo n.º 1
0
def hatchplot_fit(xp: XPS_experiment,
                  region: str,
                  fitRes: ModelResult,
                  lb: str = None,
                  marker='o',
                  ls: str = 'solid',
                  colc: str = None,
                  ax=None,
                  plot_comps: bool = True,
                  flag_fill: bool = False):
    """"Plot fit result with predefined hatch patterns for each component (up to three components)"""
    if ax == None: ax = plt.gca()
    if lb == None: lb = xp.name
    if colc == None: colc = xp.color

    p1 = ax.scatter(xp.dfx[region].energy,
                    xp.dfx[region].counts,
                    marker=marker,
                    label=lb,
                    zorder=1)
    p1.set_color(colc)

    x = xp.dfx[region].dropna().energy

    ax.plot(x,
            fitRes.best_fit,
            linestyle=ls,
            color=colc,
            lw=1.5,
            label='Fit, $\chi^2_N$ = %i' % fitRes.redchi)
    hatch = ['//', 'ox', '+']

    if plot_comps:
        comps = fitRes.eval_components(x=x)
        for i, compo in enumerate(comps):
            posx = fitRes.best_values[compo + 'center']
            ax.text(x=posx,
                    y=comps[compo].max() * 1.02,
                    s='%.1f' % posx,
                    fontsize=12)
            ax.fill_between(x,
                            y1=0,
                            y2=comps[compo],
                            alpha=1,
                            label='Component @ %.1f eV' % posx,
                            facecolor='w',
                            hatch=hatch[i],
                            edgecolor=colc,
                            zorder=-1)
    ax.legend(loc='best')  #, bbox_to_anchor=(1.12, 0.5), fontsize=16)
    cosmetics_plot()
    return ax
Ejemplo n.º 2
0
def plot_fit_result(xp: XPS_experiment,
                    region: str,
                    fitRes: ModelResult,
                    lb: str = None,
                    ax=None,
                    plot_comps: bool = True,
                    flag_fill: bool = False):
    if ax == None: ax = plt.gca()
    col = plot_region(xp, region, ax=ax, lb=lb).get_color()

    x = xp.dfx[region].dropna().energy

    ax.plot(x,
            fitRes.best_fit,
            '--',
            color=col,
            lw=1.5,
            label='best fit, $\chi^2_N$ = %i' % fitRes.redchi)
    ax.legend()

    if plot_comps:
        comps = fitRes.eval_components(x=x)
        for compo in comps:
            posx = fitRes.best_values[compo + 'center']
            colc = ax.plot(x,
                           comps[compo],
                           ls='dotted',
                           lw=1.5,
                           color=col,
                           label='__nolabel__')[0].get_color()

            ax.vlines(x=posx,
                      ymin=0,
                      ymax=comps[compo].max(),
                      linestyle='dotted',
                      colors=col)
            ax.text(x=posx,
                    y=comps[compo].max() * 0.9,
                    s='%.1f' % posx,
                    fontsize=12)
            if flag_fill:
                ax.fill_between(x,
                                y1=0,
                                y2=comps[compo],
                                alpha=0.3,
                                color=colc)

    return ax