striplog/striplog.py
def hist(self,
             lumping=None,
             summary=False,
             sort=True,
             plot=True,
             legend=None,
             ax=None
             ):
        """
        Plots a histogram and returns the data for it.

        Args:
            lumping (str): If given, the bins will be lumped based on this
                attribute of the primary components of the intervals
                encountered.
            summary (bool): If True, the summaries of the components are
                returned as the bins. Otherwise, the default behaviour is to
                return the Components themselves.
            sort (bool): If True (default), the histogram is sorted by value,
                starting with the largest.
            plot (bool): If True (default), produce a bar plot.
            legend (Legend): The legend with which to colour the bars.
            ax (axis): An axis object, which will be returned if provided.
                If you don't provide one, it will be created but not returned.

        Returns:
            Tuple: A tuple of tuples of entities and counts.

        TODO:
            Deal with numeric properties, so I can histogram 'Vp' values, say.
        """
        # This seems like overkill, but collecting all this stuff gives
        # the user some choice about what they get back.
        comps = []
        labels = []
        entries = defaultdict(int)
        for i in self:
            if lumping:
                k = i.primary[lumping]
            else:
                if summary:
                    k = i.primary.summary()
                else:
                    k = i.primary
            comps.append(i.primary)
            labels.append(i.primary.summary())
            entries[k] += i.thickness

        if sort:
            allitems = sorted(entries.items(), key=lambda i: i[1], reverse=True)
            ents, counts = zip(*allitems)
        else:
            ents, counts = tuple(entries.keys()), tuple(entries.values())

        # Make plot.
        if plot:
            if ax is None:
                fig, ax = plt.subplots()
                return_ax = False
            else:
                return_ax = True
            ind = np.arange(len(ents))
            bars = ax.bar(ind, counts, align='center')
            ax.set_xticks(ind)
            ax.set_xticklabels(labels)
            if legend:
                colours = [legend.get_colour(c) for c in comps]
                for b, c in zip(bars, colours):
                    b.set_color(c)
            ax.set_ylabel('Thickness [m]')
        else:
            bars = []

        if plot and return_ax:
            return counts, ents, ax

        return counts, ents, bars
def hist(self,
             lumping=None,
             summary=False,
             sort=True,
             plot=True,
             legend=None,
             ax=None
             ):
        # This seems like overkill, but collecting all this stuff gives
        # the user some choice about what they get back.
        comps = []
        labels = []
        entries = defaultdict(int)
        for i in self:
            if lumping:
                k = i.primary[lumping]
            else:
                if summary:
                    k = i.primary.summary()
                else:
                    k = i.primary
            comps.append(i.primary)
            labels.append(i.primary.summary())
            entries[k] += i.thickness

        if sort:
            allitems = sorted(entries.items(), key=lambda i: i[1], reverse=True)
            ents, counts = zip(*allitems)
        else:
            ents, counts = tuple(entries.keys()), tuple(entries.values())

        # Make plot.
        if plot:
            if ax is None:
                fig, ax = plt.subplots()
                return_ax = False
            else:
                return_ax = True
            ind = np.arange(len(ents))
            bars = ax.bar(ind, counts, align='center')
            ax.set_xticks(ind)
            ax.set_xticklabels(labels)
            if legend:
                colours = [legend.get_colour(c) for c in comps]
                for b, c in zip(bars, colours):
                    b.set_color(c)
            ax.set_ylabel('Thickness [m]')
        else:
            bars = []

        if plot and return_ax:
            return counts, ents, ax

        return counts, ents, bars
def hist ( self , lumping = None , summary = False , sort = True , plot = True , legend = None , ax = None ) : # This seems like overkill, but collecting all this stuff gives # the user some choice about what they get back. comps = [ ] labels = [ ] entries = defaultdict ( int ) for i in self : if lumping : k = i . primary [ lumping ] else : if summary : k = i . primary . summary ( ) else : k = i . primary comps . append ( i . primary ) labels . append ( i . primary . summary ( ) ) entries [ k ] += i . thickness if sort : allitems = sorted ( entries . items ( ) , key = lambda i : i [ 1 ] , reverse = True ) ents , counts = zip ( * allitems ) else : ents , counts = tuple ( entries . keys ( ) ) , tuple ( entries . values ( ) ) # Make plot. if plot : if ax is None : fig , ax = plt . subplots ( ) return_ax = False else : return_ax = True ind = np . arange ( len ( ents ) ) bars = ax . bar ( ind , counts , align = 'center' ) ax . set_xticks ( ind ) ax . set_xticklabels ( labels ) if legend : colours = [ legend . get_colour ( c ) for c in comps ] for b , c in zip ( bars , colours ) : b . set_color ( c ) ax . set_ylabel ( 'Thickness [m]' ) else : bars = [ ] if plot and return_ax : return counts , ents , ax return counts , ents , bars
Plots a histogram and returns the data for it.

        Args:
            lumping (str): If given, the bins will be lumped based on this
                attribute of the primary components of the intervals
                encountered.
            summary (bool): If True, the summaries of the components are
                returned as the bins. Otherwise, the default behaviour is to
                return the Components themselves.
            sort (bool): If True (default), the histogram is sorted by value,
                starting with the largest.
            plot (bool): If True (default), produce a bar plot.
            legend (Legend): The legend with which to colour the bars.
            ax (axis): An axis object, which will be returned if provided.
                If you don't provide one, it will be created but not returned.

        Returns:
            Tuple: A tuple of tuples of entities and counts.

        TODO:
            Deal with numeric properties, so I can histogram 'Vp' values, say.
Plots a histogram and returns the data for it .