Supplement/comparison_tools/plots.py
def bland_altman(x, y, interval=None, indep_conf=None, ax=None, c=None, **kwargs):
    """
    Draw a Bland-Altman plot of x and y data.
    
    https://en.wikipedia.org/wiki/Bland%E2%80%93Altman_plot
    
    Parameters
    ----------
    x, y : array-like
        x and y data to compare.
    interval : float
        Percentile band to draw on the residuals.
    indep_conf : float
        Independently determined confidence interval
        to draw on the plot
    ax : matplotlib.axesobject
        The axis on which to draw the plot
    **kwargs
        Passed to ax.scatter
    """
    ret = False
    
    if ax is None:
        fig, ax = plt.subplots(1, 1)
        ret = True
        
    # NaN screening
    ind = ~(np.isnan(x) | np.isnan(y))
    x = x[ind]
    y = y[ind]
    
    xy_mean = (x + y) / 2
    xy_resid = (y - x)

    ax.scatter(xy_mean, xy_resid, lw=0.5, edgecolor='k', alpha=0.6, c=c, s=15, **kwargs)

    # markup
    ax.axhline(0, ls='dashed', c='k', alpha=0.6, zorder=-1)
    
    ax.axhline(np.median(xy_resid), ls='dashed', c=c, alpha=0.8)
    
    if interval is not None:
        perc = 100 - interval * 100
        ints = [perc / 2, 100 - perc / 2]
        lims = np.percentile(xy_resid, ints)
        ax.axhspan(*lims, color=c, alpha=0.1, zorder=-3)
    
    if indep_conf is not None:
        ax.axhspan(-indep_conf, indep_conf, color=(0,0,0,0.1), zorder=-2)

    # labels
    ax.set_ylabel('y - x')
    ax.set_xlabel('mean (x, y)')
    
    if ret:
        return fig, ax
def bland_altman(x, y, interval=None, indep_conf=None, ax=None, c=None, **kwargs):
    """
    Draw a Bland-Altman plot of x and y data.
    
    https://en.wikipedia.org/wiki/Bland%E2%80%93Altman_plot
    
    Parameters
    ----------
    x, y : array-like
        x and y data to compare.
    interval : float
        Percentile band to draw on the residuals.
    indep_conf : float
        Independently determined confidence interval
        to draw on the plot
    ax : matplotlib.axesobject
        The axis on which to draw the plot
    **kwargs
        Passed to ax.scatter
    """
    ret = False
    
    if ax is None:
        fig, ax = plt.subplots(1, 1)
        ret = True
        
    # NaN screening
    ind = ~(np.isnan(x) | np.isnan(y))
    x = x[ind]
    y = y[ind]
    
    xy_mean = (x + y) / 2
    xy_resid = (y - x)

    ax.scatter(xy_mean, xy_resid, lw=0.5, edgecolor='k', alpha=0.6, c=c, s=15, **kwargs)

    # markup
    ax.axhline(0, ls='dashed', c='k', alpha=0.6, zorder=-1)
    
    ax.axhline(np.median(xy_resid), ls='dashed', c=c, alpha=0.8)
    
    if interval is not None:
        perc = 100 - interval * 100
        ints = [perc / 2, 100 - perc / 2]
        lims = np.percentile(xy_resid, ints)
        ax.axhspan(*lims, color=c, alpha=0.1, zorder=-3)
    
    if indep_conf is not None:
        ax.axhspan(-indep_conf, indep_conf, color=(0,0,0,0.1), zorder=-2)

    # labels
    ax.set_ylabel('y - x')
    ax.set_xlabel('mean (x, y)')
    
    if ret:
        return fig, ax
def bland_altman ( x , y , interval = None , indep_conf = None , ax = None , c = None , * * kwargs ) : ret = False if ax is None : fig , ax = plt . subplots ( 1 , 1 ) ret = True # NaN screening ind = ~ ( np . isnan ( x ) | np . isnan ( y ) ) x = x [ ind ] y = y [ ind ] xy_mean = ( x + y ) / 2 xy_resid = ( y - x ) ax . scatter ( xy_mean , xy_resid , lw = 0.5 , edgecolor = 'k' , alpha = 0.6 , c = c , s = 15 , * * kwargs ) # markup ax . axhline ( 0 , ls = 'dashed' , c = 'k' , alpha = 0.6 , zorder = - 1 ) ax . axhline ( np . median ( xy_resid ) , ls = 'dashed' , c = c , alpha = 0.8 ) if interval is not None : perc = 100 - interval * 100 ints = [ perc / 2 , 100 - perc / 2 ] lims = np . percentile ( xy_resid , ints ) ax . axhspan ( * lims , color = c , alpha = 0.1 , zorder = - 3 ) if indep_conf is not None : ax . axhspan ( - indep_conf , indep_conf , color = ( 0 , 0 , 0 , 0.1 ) , zorder = - 2 ) # labels ax . set_ylabel ( 'y - x' ) ax . set_xlabel ( 'mean (x, y)' ) if ret : return fig , ax
Draw a Bland-Altman plot of x and y data.
    
    https://en.wikipedia.org/wiki/Bland%E2%80%93Altman_plot
    
    Parameters
    ----------
    x, y : array-like
        x and y data to compare.
    interval : float
        Percentile band to draw on the residuals.
    indep_conf : float
        Independently determined confidence interval
        to draw on the plot
    ax : matplotlib.axesobject
        The axis on which to draw the plot
    **kwargs
        Passed to ax.scatter
Draw a Bland - Altman plot of x and y data . https : // en . wikipedia . org / wiki / Bland%E2%80%93Altman_plot Parameters ---------- x y : array - like x and y data to compare . interval : float Percentile band to draw on the residuals . indep_conf : float Independently determined confidence interval to draw on the plot ax : matplotlib . axesobject The axis on which to draw the plot ** kwargs Passed to ax . scatter