Skip to content

Plotting Position#

statista.distributions.PlottingPosition #

PlottingPosition.

Source code in src/statista/distributions/base.py
class PlottingPosition:
    """PlottingPosition."""

    @staticmethod
    def return_period(prob_non_exceed: list | np.ndarray) -> np.ndarray:
        """Return Period.

        Args:
            prob_non_exceed:
                non-exceedance probability.

        Returns:
            array:
                calculated return period.

        Examples:
            - First generate some random numbers between 0 and 1 as a non-exceedance probability. then use this non-exceedance
                to calculate the return period.
                ```python
                >>> import numpy as np
                >>> from statista.distributions import PlottingPosition
                >>> data = np.random.random(15)
                >>> rp = PlottingPosition.return_period(data)
                >>> print(rp) # doctest: +SKIP
                [ 1.33088992  4.75342173  2.46855419  1.42836548  2.75320582  2.2268505
                  8.06500888 10.56043917 18.28884687  1.10298241  1.2113997   1.40988022
                  1.02795867  1.01326322  1.05572108]

                ```
        """
        if any(np.asarray(prob_non_exceed) > 1):
            raise ValueError("Non-exceedance probability should be less than 1")
        prob_non_exceed = np.array(prob_non_exceed)
        t = 1 / (1 - prob_non_exceed)
        return t

    @staticmethod
    def weibul(data: list | np.ndarray, return_period: int = False) -> np.ndarray:
        """Weibul.

        Weibul method to calculate the cumulative distribution function cdf or
        return period.

        Args:
            data:
                list/array of the data.
            return_period:
                False to calculate the cumulative distribution function cdf or True to calculate the return period.
                Default=False

        Returns:
            cdf/T:
                cumulative distribution function or return period.

        Examples:
            ```python
            >>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
            >>> cdf = PlottingPosition.weibul(data)
            >>> print(cdf)
            [0.09090909 0.18181818 0.27272727 0.36363636 0.45454545 0.54545455
             0.63636364 0.72727273 0.81818182 0.90909091]

            ```
        """
        data = np.array(data)
        data.sort()
        n = len(data)
        cdf = np.array(range(1, n + 1)) / (n + 1)
        if not return_period:
            return cdf
        else:
            t = PlottingPosition.return_period(cdf)
            return t

return_period(prob_non_exceed) staticmethod #

Return Period.

Parameters:

Name Type Description Default
prob_non_exceed list | ndarray

non-exceedance probability.

required

Returns:

Name Type Description
array ndarray

calculated return period.

Examples:

  • First generate some random numbers between 0 and 1 as a non-exceedance probability. then use this non-exceedance to calculate the return period.
    >>> import numpy as np
    >>> from statista.distributions import PlottingPosition
    >>> data = np.random.random(15)
    >>> rp = PlottingPosition.return_period(data)
    >>> print(rp) # doctest: +SKIP
    [ 1.33088992  4.75342173  2.46855419  1.42836548  2.75320582  2.2268505
      8.06500888 10.56043917 18.28884687  1.10298241  1.2113997   1.40988022
      1.02795867  1.01326322  1.05572108]
    
Source code in src/statista/distributions/base.py
@staticmethod
def return_period(prob_non_exceed: list | np.ndarray) -> np.ndarray:
    """Return Period.

    Args:
        prob_non_exceed:
            non-exceedance probability.

    Returns:
        array:
            calculated return period.

    Examples:
        - First generate some random numbers between 0 and 1 as a non-exceedance probability. then use this non-exceedance
            to calculate the return period.
            ```python
            >>> import numpy as np
            >>> from statista.distributions import PlottingPosition
            >>> data = np.random.random(15)
            >>> rp = PlottingPosition.return_period(data)
            >>> print(rp) # doctest: +SKIP
            [ 1.33088992  4.75342173  2.46855419  1.42836548  2.75320582  2.2268505
              8.06500888 10.56043917 18.28884687  1.10298241  1.2113997   1.40988022
              1.02795867  1.01326322  1.05572108]

            ```
    """
    if any(np.asarray(prob_non_exceed) > 1):
        raise ValueError("Non-exceedance probability should be less than 1")
    prob_non_exceed = np.array(prob_non_exceed)
    t = 1 / (1 - prob_non_exceed)
    return t

weibul(data, return_period=False) staticmethod #

Weibul.

Weibul method to calculate the cumulative distribution function cdf or return period.

Parameters:

Name Type Description Default
data list | ndarray

list/array of the data.

required
return_period int

False to calculate the cumulative distribution function cdf or True to calculate the return period. Default=False

False

Returns:

Type Description
ndarray

cdf/T: cumulative distribution function or return period.

Examples:

>>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> cdf = PlottingPosition.weibul(data)
>>> print(cdf)
[0.09090909 0.18181818 0.27272727 0.36363636 0.45454545 0.54545455
 0.63636364 0.72727273 0.81818182 0.90909091]
Source code in src/statista/distributions/base.py
@staticmethod
def weibul(data: list | np.ndarray, return_period: int = False) -> np.ndarray:
    """Weibul.

    Weibul method to calculate the cumulative distribution function cdf or
    return period.

    Args:
        data:
            list/array of the data.
        return_period:
            False to calculate the cumulative distribution function cdf or True to calculate the return period.
            Default=False

    Returns:
        cdf/T:
            cumulative distribution function or return period.

    Examples:
        ```python
        >>> data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        >>> cdf = PlottingPosition.weibul(data)
        >>> print(cdf)
        [0.09090909 0.18181818 0.27272727 0.36363636 0.45454545 0.54545455
         0.63636364 0.72727273 0.81818182 0.90909091]

        ```
    """
    data = np.array(data)
    data.sort()
    n = len(data)
    cdf = np.array(range(1, n + 1)) / (n + 1)
    if not return_period:
        return cdf
    else:
        t = PlottingPosition.return_period(cdf)
        return t