Supplement/comparison_tools/plots_1sample.py
def residual_plots(df, rep_stats=None, els=['Mg', 'Sr', 'Al', 'Mn', 'Fe', 'Cu', 'Zn', 'B']):
    """
    Function for plotting Test User and LAtools data comparison.

    Parameters
    ----------
    df : pandas.DataFrame
        A dataframe containing reference ('X/Ca_r'), test user 
        ('X/Ca_t') and LAtools ('X123') data.
    rep_stats : dict
        Reproducibility stats of the reference data produced by
        `pairwise_reproducibility`
    els : list
        list of elements (names only) to plot.
    """
    
    # get corresponding analyte and ratio names
    As = []
    Rs = []
    analytes = [c for c in df.columns if ('/' not in c)]
    ratios = [c for c in df.columns if ('/' in c)]

    for e in els:
        if e == 'Sr':
            As.append('88Sr')
        elif e == 'Mg':
            As.append('24Mg')
        else:
            As.append([a for a in analytes if e in a][0])
        Rs.append([r for r in ratios if e in r][0])
    
    fig, axs = plt.subplots(len(els), 2, figsize=(5, len(els) * 2))
    
    for i, (e, a) in enumerate(zip(Rs, As)):
        lax, hax = axs[i]
        
        x = df.loc[:, e].values
        yl = df.loc[:, a].values
        
        c = element_colour(fmt_el(a))
        u = 'mmol/mol'
        
        # calculate residuals
        rl = yl - x
        
        # plot residuals
        lax.scatter(x, rl, c=c, s=15, lw=0.5, edgecolor='k', alpha=0.5)
        
        # plot PDFs
        rl = rl[~np.isnan(rl)]
        lims = np.percentile(rl, [99, 1])
        lims += lims.ptp() * np.array((-1.25, 1.25))
        bins = np.linspace(*lims, 100)
        kdl = stats.gaussian_kde(rl, .4)
        hax.fill_betweenx(bins, kdl(bins), facecolor=c, alpha=0.7, edgecolor='k', lw=0.5, label='LAtools')
        hax.set_xlim([0, hax.get_xlim()[-1]])
                
        # axis labels, annotations and limits
        lax.set_ylabel(e + ' ('+ u + ')')
        lax.text(.02,.02,fmt_RSS(rl), fontsize=8,
                 ha='left', va='bottom', transform=lax.transAxes)

        xlim = np.percentile(x[~np.isnan(x)], [0, 98])
        lax.set_xlim(xlim)
        
        for ax in axs[i]:
            ax.set_ylim(lims)
            # zero line and 2SD precision
            ax.axhline(0, c='k', ls='dashed', alpha=0.6)
            if rep_stats is not None:
                ax.axhspan(-rep_stats[e][0] * 2, rep_stats[e][0] * 2, color=(0,0,0,0.2), zorder=-1)
            
            if not ax.is_first_col():
                ax.set_yticklabels([])
                
            if ax.is_last_row():
                hax.set_xlabel('Density')
                lax.set_xlabel('Iolite User')

            if ax.is_first_row():
                lax.set_title('LAtools', loc='left')
            
    fig.tight_layout()

    return fig, axs
def residual_plots(df, rep_stats=None, els=['Mg', 'Sr', 'Al', 'Mn', 'Fe', 'Cu', 'Zn', 'B']):
    """
    Function for plotting Test User and LAtools data comparison.

    Parameters
    ----------
    df : pandas.DataFrame
        A dataframe containing reference ('X/Ca_r'), test user 
        ('X/Ca_t') and LAtools ('X123') data.
    rep_stats : dict
        Reproducibility stats of the reference data produced by
        `pairwise_reproducibility`
    els : list
        list of elements (names only) to plot.
    """
    
    # get corresponding analyte and ratio names
    As = []
    Rs = []
    analytes = [c for c in df.columns if ('/' not in c)]
    ratios = [c for c in df.columns if ('/' in c)]

    for e in els:
        if e == 'Sr':
            As.append('88Sr')
        elif e == 'Mg':
            As.append('24Mg')
        else:
            As.append([a for a in analytes if e in a][0])
        Rs.append([r for r in ratios if e in r][0])
    
    fig, axs = plt.subplots(len(els), 2, figsize=(5, len(els) * 2))
    
    for i, (e, a) in enumerate(zip(Rs, As)):
        lax, hax = axs[i]
        
        x = df.loc[:, e].values
        yl = df.loc[:, a].values
        
        c = element_colour(fmt_el(a))
        u = 'mmol/mol'
        
        # calculate residuals
        rl = yl - x
        
        # plot residuals
        lax.scatter(x, rl, c=c, s=15, lw=0.5, edgecolor='k', alpha=0.5)
        
        # plot PDFs
        rl = rl[~np.isnan(rl)]
        lims = np.percentile(rl, [99, 1])
        lims += lims.ptp() * np.array((-1.25, 1.25))
        bins = np.linspace(*lims, 100)
        kdl = stats.gaussian_kde(rl, .4)
        hax.fill_betweenx(bins, kdl(bins), facecolor=c, alpha=0.7, edgecolor='k', lw=0.5, label='LAtools')
        hax.set_xlim([0, hax.get_xlim()[-1]])
                
        # axis labels, annotations and limits
        lax.set_ylabel(e + ' ('+ u + ')')
        lax.text(.02,.02,fmt_RSS(rl), fontsize=8,
                 ha='left', va='bottom', transform=lax.transAxes)

        xlim = np.percentile(x[~np.isnan(x)], [0, 98])
        lax.set_xlim(xlim)
        
        for ax in axs[i]:
            ax.set_ylim(lims)
            # zero line and 2SD precision
            ax.axhline(0, c='k', ls='dashed', alpha=0.6)
            if rep_stats is not None:
                ax.axhspan(-rep_stats[e][0] * 2, rep_stats[e][0] * 2, color=(0,0,0,0.2), zorder=-1)
            
            if not ax.is_first_col():
                ax.set_yticklabels([])
                
            if ax.is_last_row():
                hax.set_xlabel('Density')
                lax.set_xlabel('Iolite User')

            if ax.is_first_row():
                lax.set_title('LAtools', loc='left')
            
    fig.tight_layout()

    return fig, axs
def residual_plots ( df , rep_stats = None , els = [ 'Mg' , 'Sr' , 'Al' , 'Mn' , 'Fe' , 'Cu' , 'Zn' , 'B' ] ) : # get corresponding analyte and ratio names As = [ ] Rs = [ ] analytes = [ c for c in df . columns if ( '/' not in c ) ] ratios = [ c for c in df . columns if ( '/' in c ) ] for e in els : if e == 'Sr' : As . append ( '88Sr' ) elif e == 'Mg' : As . append ( '24Mg' ) else : As . append ( [ a for a in analytes if e in a ] [ 0 ] ) Rs . append ( [ r for r in ratios if e in r ] [ 0 ] ) fig , axs = plt . subplots ( len ( els ) , 2 , figsize = ( 5 , len ( els ) * 2 ) ) for i , ( e , a ) in enumerate ( zip ( Rs , As ) ) : lax , hax = axs [ i ] x = df . loc [ : , e ] . values yl = df . loc [ : , a ] . values c = element_colour ( fmt_el ( a ) ) u = 'mmol/mol' # calculate residuals rl = yl - x # plot residuals lax . scatter ( x , rl , c = c , s = 15 , lw = 0.5 , edgecolor = 'k' , alpha = 0.5 ) # plot PDFs rl = rl [ ~ np . isnan ( rl ) ] lims = np . percentile ( rl , [ 99 , 1 ] ) lims += lims . ptp ( ) * np . array ( ( - 1.25 , 1.25 ) ) bins = np . linspace ( * lims , 100 ) kdl = stats . gaussian_kde ( rl , .4 ) hax . fill_betweenx ( bins , kdl ( bins ) , facecolor = c , alpha = 0.7 , edgecolor = 'k' , lw = 0.5 , label = 'LAtools' ) hax . set_xlim ( [ 0 , hax . get_xlim ( ) [ - 1 ] ] ) # axis labels, annotations and limits lax . set_ylabel ( e + ' (' + u + ')' ) lax . text ( .02 , .02 , fmt_RSS ( rl ) , fontsize = 8 , ha = 'left' , va = 'bottom' , transform = lax . transAxes ) xlim = np . percentile ( x [ ~ np . isnan ( x ) ] , [ 0 , 98 ] ) lax . set_xlim ( xlim ) for ax in axs [ i ] : ax . set_ylim ( lims ) # zero line and 2SD precision ax . axhline ( 0 , c = 'k' , ls = 'dashed' , alpha = 0.6 ) if rep_stats is not None : ax . axhspan ( - rep_stats [ e ] [ 0 ] * 2 , rep_stats [ e ] [ 0 ] * 2 , color = ( 0 , 0 , 0 , 0.2 ) , zorder = - 1 ) if not ax . is_first_col ( ) : ax . set_yticklabels ( [ ] ) if ax . is_last_row ( ) : hax . set_xlabel ( 'Density' ) lax . set_xlabel ( 'Iolite User' ) if ax . is_first_row ( ) : lax . set_title ( 'LAtools' , loc = 'left' ) fig . tight_layout ( ) return fig , axs
Function for plotting Test User and LAtools data comparison.

    Parameters
    ----------
    df : pandas.DataFrame
        A dataframe containing reference ('X/Ca_r'), test user 
        ('X/Ca_t') and LAtools ('X123') data.
    rep_stats : dict
        Reproducibility stats of the reference data produced by
        `pairwise_reproducibility`
    els : list
        list of elements (names only) to plot.
Function for plotting Test User and LAtools data comparison .