<commit_before>"""This module contains all the plotting methods in Pastas.

Pastas models come with a number of predefined plotting methods to quickly
visualize a Model. All of these methods are contained in the `plot`
attribute of a model. For example, if we stored a :class:`pastas.model.Model`
instance in the variable `ml`, the plot methods are available as follows::

    ml.plot.decomposition()
"""

import logging

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator, LogFormatter
from pandas import DataFrame, Timestamp, concat

from .decorators import model_tmin_tmax
from .stats import diagnostics, plot_cum_frequency, plot_diagnostics

logger = logging.getLogger(__name__)


def _table_formatter_params(s):
    """Internal method for formatting parameters in tables in Pastas plots.

    Parameters
    ----------
    s : float
        value to format

    Returns
    -------
    str
        float formatted as str
    """
    if np.floor(np.log10(np.abs(s))) <= -2:
        return f"{s:.2e}"
    elif np.floor(np.log10(np.abs(s))) > 5:
        return f"{s:.2e}"
    else:
        return f"{s:.2f}"


def _table_formatter_stderr(s):
    """Internal method for formatting stderrs in tables in Pastas plots.

    Parameters
    ----------
    s : float
        value to format

    Returns
    -------
    str
        float formatted as str
    """
    if np.floor(np.log10(np.abs(s))) <= -4:
        return f"{s * 100.:.2e}%"
    elif np.floor(np.log10(np.abs(s))) > 3:
        return f"{s * 100.:.2e}%"
    else:
        return f"{s:.2%}"


class Plotting:
    """Plots available directly from the Model Class."""

    def __init__(self, ml):
        self.ml = ml  # Store a reference to the model class

    def __repr__(self):
        msg = "This module contains all the built-in plotting options that " \
              "are available."
        return msg

    @model_tmin_tmax
    def plot(self, tmin=None, tmax=None, oseries=True, simulation=True,
             ax=None, figsize=None, legend=True, **kwargs):
        """Make a plot of the observed and simulated series.

        Parameters<commit_msg>Replace nan in plots by empty values<commit_after>"""This module contains all the plotting methods in Pastas.

Pastas models come with a number of predefined plotting methods to quickly
visualize a Model. All of these methods are contained in the `plot`
attribute of a model. For example, if we stored a :class:`pastas.model.Model`
instance in the variable `ml`, the plot methods are available as follows::

    ml.plot.decomposition()
"""

import logging

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator, LogFormatter
from pandas import DataFrame, Timestamp, concat

from .decorators import model_tmin_tmax
from .stats import diagnostics, plot_cum_frequency, plot_diagnostics

logger = logging.getLogger(__name__)


def _table_formatter_params(s):
    """Internal method for formatting parameters in tables in Pastas plots.

    Parameters
    ----------
    s : float
        value to format

    Returns
    -------
    str
        float formatted as str
    """
    if np.isnan(s):
        return ''
    elif np.floor(np.log10(np.abs(s))) <= -2:
        return f"{s:.2e}"
    elif np.floor(np.log10(np.abs(s))) > 5:
        return f"{s:.2e}"
    else:
        return f"{s:.2f}"


def _table_formatter_stderr(s):
    """Internal method for formatting stderrs in tables in Pastas plots.

    Parameters
    ----------
    s : float
        value to format

    Returns
    -------
    str
        float formatted as str
    """
    if np.isnan(s):
        return ''
    elif np.floor(np.log10(np.abs(s))) <= -4:
        return f"{s * 100.:.2e}%"
    elif np.floor(np.log10(np.abs(s))) > 3:
        return f"{s * 100.:.2e}%"
    else:
        return f"{s:.2%}"


class Plotting:
    """Plots available directly from the Model Class."""

    def __init__(self, ml):
        self.ml = ml  # Store a reference to the model class

    def __repr__(self):
        msg = "This module contains all the built-in plotting options that " \
              "are available."
        return msg

    @model_tmin_tmax
    def plot(self, tmin=None, tmax=None, oseries=True, simulation=True,
             ax=None, figsize=None, legend=True, **kwargs):
        """Make a plot of the observed and simulated series.

        Parameters
{'fraction_non_alphanumeric': 0.11254237288135593, 'fraction_numerical': 0.010847457627118645, 'mean_word_length': 2.566478646253022, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2830230', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1304, 'n_words': 459}