(self, max_width=78, show_bars=True, show_counts=True)
return "\n".join(result)
Returns the string representation of the histogram.

        @param max_width: the maximal width of each line of the string
          This value may not be obeyed if it is too small.
        @param show_bars: specify whether the histogram bars should be shown
        @param show_counts: specify whether the histogram counts should be
          shown. If both I{show_bars} and I{show_counts} are C{False},
          only a general descriptive statistics (number of elements, mean and
          standard deviation) is shown.
Returns the string representation of the histogram.
Returns the string representation of the histogram .
def to_string(self, max_width=78, show_bars=True, show_counts=True):
        """Returns the string representation of the histogram.

        @param max_width: the maximal width of each line of the string
          This value may not be obeyed if it is too small.
        @param show_bars: specify whether the histogram bars should be shown
        @param show_counts: specify whether the histogram counts should be
          shown. If both I{show_bars} and I{show_counts} are C{False},
          only a general descriptive statistics (number of elements, mean and
          standard deviation) is shown.
        """

        if self._min is None or self._max is None:
            return "N = 0"

        # Determine how many decimal digits should we use
        if int(self._min) == self._min and int(self._bin_width) == self._bin_width:
            number_format = "%d"
        else:
            number_format = "%.3f"
        num_length = max(len(number_format % self._min), len(number_format % self._max))
        number_format = "%" + str(num_length) + number_format[1:]
        format_string = "[%s, %s): %%s" % (number_format, number_format)

        # Calculate the scale of the bars on the histogram
        if show_bars:
            maxval = max(self._bins)
            if show_counts:
                maxval_length = len(str(maxval))
                scale = maxval // (max_width - 2 * num_length - maxval_length - 9)
            else:
                scale = maxval // (max_width - 2 * num_length - 6)
            scale = max(scale, 1)

        result = ["N = %d, mean +- sd: %.4f +- %.4f" % (self.n, self.mean, self.sd)]

        if show_bars:
            # Print the bars
            if scale > 1:
                result.append("Each * represents %d items" % scale)
            if show_counts:
                format_string += " (%d)"
                for left, right, cnt in self.bins():
                    result.append(
                        format_string % (left, right, "*" * (cnt // scale), cnt)
                    )
            else:
                for left, right, cnt in self.bins():
                    result.append(format_string % (left, right, "*" * (cnt // scale)))
        elif show_counts:
            # Print the counts only
            for left, right, cnt in self.bins():
                result.append(format_string % (left, right, cnt))

        return "\n".join(result)
def to_string ( self , max_width = 78 , show_bars = True , show_counts = True ) : if self . _min is None or self . _max is None : return "N = 0" # Determine how many decimal digits should we use if int ( self . _min ) == self . _min and int ( self . _bin_width ) == self . _bin_width : number_format = "%d" else : number_format = "%.3f" num_length = max ( len ( number_format % self . _min ) , len ( number_format % self . _max ) ) number_format = "%" + str ( num_length ) + number_format [ 1 : ] format_string = "[%s, %s): %%s" % ( number_format , number_format ) # Calculate the scale of the bars on the histogram if show_bars : maxval = max ( self . _bins ) if show_counts : maxval_length = len ( str ( maxval ) ) scale = maxval // ( max_width - 2 * num_length - maxval_length - 9 ) else : scale = maxval // ( max_width - 2 * num_length - 6 ) scale = max ( scale , 1 ) result = [ "N = %d, mean +- sd: %.4f +- %.4f" % ( self . n , self . mean , self . sd ) ] if show_bars : # Print the bars if scale > 1 : result . append ( "Each * represents %d items" % scale ) if show_counts : format_string += " (%d)" for left , right , cnt in self . bins ( ) : result . append ( format_string % ( left , right , "*" * ( cnt // scale ) , cnt ) ) else : for left , right , cnt in self . bins ( ) : result . append ( format_string % ( left , right , "*" * ( cnt // scale ) ) ) elif show_counts : # Print the counts only for left , right , cnt in self . bins ( ) : result . append ( format_string % ( left , right , cnt ) ) return "\n" . join ( result )