How to use the probscale.formatters._FormatterMixin function in probscale

To help you get started, we’ve selected a few probscale examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github matplotlib / mpl-probscale / probscale / formatters.py View on Github external
>>> fmt = formatters.PctFormatter()
    >>> fmt(0.2)
    '0.2'
    >>> fmt(10)
    '10'
    >>> fmt(99.999)
    '99.999'

    """

    factor = 1.0
    offset = 2
    top = 100


class ProbFormatter(_FormatterMixin):
    """
    Formatter class for MPL axes to display probabilities as decimals.

    Examples
    --------
    >>> from probscale import formatters
    >>> fmt = formatters.ProbFormatter()
    >>> fmt(0.01)
    '0.01'
    >>> fmt(0.2)
    '0.20'
    >>> try:
    ...    fmt(10.5)
    ... except(ValueError):
    ...     print('formatter out of bounds')
    formatter out of bounds
github matplotlib / mpl-probscale / probscale / formatters.py View on Github external
def __call__(self, x, pos=None):
        if x < (10 / self.factor):
            out = self._sig_figs(x, 1)
        elif x <= (99 / self.factor):
            out = self._sig_figs(x, 2)
        else:
            order = numpy.ceil(numpy.round(
                numpy.abs(numpy.log10(self.top - x)),
                6
            ))
            out = self._sig_figs(x, order + self.offset)

        return '{}'.format(out)


class PctFormatter(_FormatterMixin):
    """
    Formatter class for MPL axes to display probabilities as percentages.

    Examples
    --------
    >>> from probscale import formatters
    >>> fmt = formatters.PctFormatter()
    >>> fmt(0.2)
    '0.2'
    >>> fmt(10)
    '10'
    >>> fmt(99.999)
    '99.999'

    """