latools/D_obj.py
def crossplot_filters(self, filter_string, analytes=None):
        """
        Plot the results of a group of filters in a crossplot.

        Parameters
        ----------
        filter_string : str
            A string that identifies a group of filters.
            e.g. 'test' would plot all filters with 'test' in the
            name.
        analytes : optional, array_like or str
            The analyte(s) to plot. Defaults to all analytes.

        Returns
        -------
        fig, axes objects
        """

        if analytes is None:
            analytes = [a for a in self.analytes if 'Ca' not in a]

        # isolate relevant filters
        filts = self.filt.components.keys()
        cfilts = [f for f in filts if filter_string in f]
        flab = re.compile('.*_(.*)$')  # regex to get cluster number

        # set up axes
        numvars = len(analytes)
        fig, axes = plt.subplots(nrows=numvars, ncols=numvars,
                                 figsize=(12, 12))
        fig.subplots_adjust(hspace=0.05, wspace=0.05)

        for ax in axes.flat:
            ax.xaxis.set_visible(False)
            ax.yaxis.set_visible(False)

            if ax.is_first_col():
                ax.yaxis.set_ticks_position('left')
            if ax.is_last_col():
                ax.yaxis.set_ticks_position('right')
            if ax.is_first_row():
                ax.xaxis.set_ticks_position('top')
            if ax.is_last_row():
                ax.xaxis.set_ticks_position('bottom')

        # isolate nominal_values for all analytes
        focus = {k: nominal_values(v) for k, v in self.focus.items()}
        # determine units for all analytes
        udict = {a: unitpicker(np.nanmean(focus[a]),
                               denominator=self.internal_standard,
                               focus_stage=self.focus_stage) for a in analytes}
        # determine ranges for all analytes
        rdict = {a: (np.nanmin(focus[a] * udict[a][0]),
                     np.nanmax(focus[a] * udict[a][0])) for a in analytes}

        for f in cfilts:
            ind = self.filt.grab_filt(f)
            focus = {k: nominal_values(v[ind]) for k, v in self.focus.items()}
            lab = flab.match(f).groups()[0]
            axes[0, 0].scatter([], [], s=10, label=lab)

            for i, j in zip(*np.triu_indices_from(axes, k=1)):
                # get analytes
                ai = analytes[i]
                aj = analytes[j]

                # remove nan, apply multipliers
                pi = focus[ai][~np.isnan(focus[ai])] * udict[ai][0]
                pj = focus[aj][~np.isnan(focus[aj])] * udict[aj][0]

                # make plot
                axes[i, j].scatter(pj, pi, alpha=0.4, s=10, lw=0)
                axes[j, i].scatter(pi, pj, alpha=0.4, s=10, lw=0)

                axes[i, j].set_ylim(*rdict[ai])
                axes[i, j].set_xlim(*rdict[aj])

                axes[j, i].set_ylim(*rdict[aj])
                axes[j, i].set_xlim(*rdict[ai])

        # diagonal labels
        for a, n in zip(analytes, np.arange(len(analytes))):
            axes[n, n].annotate(a + '\n' + udict[a][1], (0.5, 0.5),
                                xycoords='axes fraction',
                                ha='center', va='center')
            axes[n, n].set_xlim(*rdict[a])
            axes[n, n].set_ylim(*rdict[a])

        axes[0, 0].legend(loc='upper left', title=filter_string, fontsize=8)

        # switch on alternating axes
        for i, j in zip(range(numvars), itertools.cycle((-1, 0))):
            axes[j, i].xaxis.set_visible(True)
            for label in axes[j, i].get_xticklabels():
                label.set_rotation(90)
            axes[i, j].yaxis.set_visible(True)

        return fig, axes
def crossplot_filters(self, filter_string, analytes=None):
        """
        Plot the results of a group of filters in a crossplot.

        Parameters
        ----------
        filter_string : str
            A string that identifies a group of filters.
            e.g. 'test' would plot all filters with 'test' in the
            name.
        analytes : optional, array_like or str
            The analyte(s) to plot. Defaults to all analytes.

        Returns
        -------
        fig, axes objects
        """

        if analytes is None:
            analytes = [a for a in self.analytes if 'Ca' not in a]

        # isolate relevant filters
        filts = self.filt.components.keys()
        cfilts = [f for f in filts if filter_string in f]
        flab = re.compile('.*_(.*)$')  # regex to get cluster number

        # set up axes
        numvars = len(analytes)
        fig, axes = plt.subplots(nrows=numvars, ncols=numvars,
                                 figsize=(12, 12))
        fig.subplots_adjust(hspace=0.05, wspace=0.05)

        for ax in axes.flat:
            ax.xaxis.set_visible(False)
            ax.yaxis.set_visible(False)

            if ax.is_first_col():
                ax.yaxis.set_ticks_position('left')
            if ax.is_last_col():
                ax.yaxis.set_ticks_position('right')
            if ax.is_first_row():
                ax.xaxis.set_ticks_position('top')
            if ax.is_last_row():
                ax.xaxis.set_ticks_position('bottom')

        # isolate nominal_values for all analytes
        focus = {k: nominal_values(v) for k, v in self.focus.items()}
        # determine units for all analytes
        udict = {a: unitpicker(np.nanmean(focus[a]),
                               denominator=self.internal_standard,
                               focus_stage=self.focus_stage) for a in analytes}
        # determine ranges for all analytes
        rdict = {a: (np.nanmin(focus[a] * udict[a][0]),
                     np.nanmax(focus[a] * udict[a][0])) for a in analytes}

        for f in cfilts:
            ind = self.filt.grab_filt(f)
            focus = {k: nominal_values(v[ind]) for k, v in self.focus.items()}
            lab = flab.match(f).groups()[0]
            axes[0, 0].scatter([], [], s=10, label=lab)

            for i, j in zip(*np.triu_indices_from(axes, k=1)):
                # get analytes
                ai = analytes[i]
                aj = analytes[j]

                # remove nan, apply multipliers
                pi = focus[ai][~np.isnan(focus[ai])] * udict[ai][0]
                pj = focus[aj][~np.isnan(focus[aj])] * udict[aj][0]

                # make plot
                axes[i, j].scatter(pj, pi, alpha=0.4, s=10, lw=0)
                axes[j, i].scatter(pi, pj, alpha=0.4, s=10, lw=0)

                axes[i, j].set_ylim(*rdict[ai])
                axes[i, j].set_xlim(*rdict[aj])

                axes[j, i].set_ylim(*rdict[aj])
                axes[j, i].set_xlim(*rdict[ai])

        # diagonal labels
        for a, n in zip(analytes, np.arange(len(analytes))):
            axes[n, n].annotate(a + '\n' + udict[a][1], (0.5, 0.5),
                                xycoords='axes fraction',
                                ha='center', va='center')
            axes[n, n].set_xlim(*rdict[a])
            axes[n, n].set_ylim(*rdict[a])

        axes[0, 0].legend(loc='upper left', title=filter_string, fontsize=8)

        # switch on alternating axes
        for i, j in zip(range(numvars), itertools.cycle((-1, 0))):
            axes[j, i].xaxis.set_visible(True)
            for label in axes[j, i].get_xticklabels():
                label.set_rotation(90)
            axes[i, j].yaxis.set_visible(True)

        return fig, axes
def crossplot_filters ( self , filter_string , analytes = None ) : if analytes is None : analytes = [ a for a in self . analytes if 'Ca' not in a ] # isolate relevant filters filts = self . filt . components . keys ( ) cfilts = [ f for f in filts if filter_string in f ] flab = re . compile ( '.*_(.*)$' ) # regex to get cluster number # set up axes numvars = len ( analytes ) fig , axes = plt . subplots ( nrows = numvars , ncols = numvars , figsize = ( 12 , 12 ) ) fig . subplots_adjust ( hspace = 0.05 , wspace = 0.05 ) for ax in axes . flat : ax . xaxis . set_visible ( False ) ax . yaxis . set_visible ( False ) if ax . is_first_col ( ) : ax . yaxis . set_ticks_position ( 'left' ) if ax . is_last_col ( ) : ax . yaxis . set_ticks_position ( 'right' ) if ax . is_first_row ( ) : ax . xaxis . set_ticks_position ( 'top' ) if ax . is_last_row ( ) : ax . xaxis . set_ticks_position ( 'bottom' ) # isolate nominal_values for all analytes focus = { k : nominal_values ( v ) for k , v in self . focus . items ( ) } # determine units for all analytes udict = { a : unitpicker ( np . nanmean ( focus [ a ] ) , denominator = self . internal_standard , focus_stage = self . focus_stage ) for a in analytes } # determine ranges for all analytes rdict = { a : ( np . nanmin ( focus [ a ] * udict [ a ] [ 0 ] ) , np . nanmax ( focus [ a ] * udict [ a ] [ 0 ] ) ) for a in analytes } for f in cfilts : ind = self . filt . grab_filt ( f ) focus = { k : nominal_values ( v [ ind ] ) for k , v in self . focus . items ( ) } lab = flab . match ( f ) . groups ( ) [ 0 ] axes [ 0 , 0 ] . scatter ( [ ] , [ ] , s = 10 , label = lab ) for i , j in zip ( * np . triu_indices_from ( axes , k = 1 ) ) : # get analytes ai = analytes [ i ] aj = analytes [ j ] # remove nan, apply multipliers pi = focus [ ai ] [ ~ np . isnan ( focus [ ai ] ) ] * udict [ ai ] [ 0 ] pj = focus [ aj ] [ ~ np . isnan ( focus [ aj ] ) ] * udict [ aj ] [ 0 ] # make plot axes [ i , j ] . scatter ( pj , pi , alpha = 0.4 , s = 10 , lw = 0 ) axes [ j , i ] . scatter ( pi , pj , alpha = 0.4 , s = 10 , lw = 0 ) axes [ i , j ] . set_ylim ( * rdict [ ai ] ) axes [ i , j ] . set_xlim ( * rdict [ aj ] ) axes [ j , i ] . set_ylim ( * rdict [ aj ] ) axes [ j , i ] . set_xlim ( * rdict [ ai ] ) # diagonal labels for a , n in zip ( analytes , np . arange ( len ( analytes ) ) ) : axes [ n , n ] . annotate ( a + '\n' + udict [ a ] [ 1 ] , ( 0.5 , 0.5 ) , xycoords = 'axes fraction' , ha = 'center' , va = 'center' ) axes [ n , n ] . set_xlim ( * rdict [ a ] ) axes [ n , n ] . set_ylim ( * rdict [ a ] ) axes [ 0 , 0 ] . legend ( loc = 'upper left' , title = filter_string , fontsize = 8 ) # switch on alternating axes for i , j in zip ( range ( numvars ) , itertools . cycle ( ( - 1 , 0 ) ) ) : axes [ j , i ] . xaxis . set_visible ( True ) for label in axes [ j , i ] . get_xticklabels ( ) : label . set_rotation ( 90 ) axes [ i , j ] . yaxis . set_visible ( True ) return fig , axes
Plot the results of a group of filters in a crossplot.

        Parameters
        ----------
        filter_string : str
            A string that identifies a group of filters.
            e.g. 'test' would plot all filters with 'test' in the
            name.
        analytes : optional, array_like or str
            The analyte(s) to plot. Defaults to all analytes.

        Returns
        -------
        fig, axes objects
Plot the results of a group of filters in a crossplot .