# Path: prospect/plotting/corner.py
# def _quantile(x, q, weights=None):
#     """Compute (weighted) quantiles from an input set of samples.
# 
#     Parameters
#     ----------
#     x : `~numpy.ndarray` with shape (nsamps,)
#         Input samples.
# 
#     q : `~numpy.ndarray` with shape (nquantiles,)
#        The list of quantiles to compute from `[0., 1.]`.
# 
#     weights : `~numpy.ndarray` with shape (nsamps,), optional
#         The associated weight from each sample.
# 
#     Returns
#     -------
#     quantiles : `~numpy.ndarray` with shape (nquantiles,)
#         The weighted sample quantiles computed at `q`.
# 
#     """
#     # Initial check.
#     x = np.atleast_1d(x)
#     q = np.atleast_1d(q)
# 
#     # Quantile check.
#     if np.any(q < 0.0) or np.any(q > 1.0):
#         raise ValueError("Quantiles must be between 0. and 1.")
# 
#     if weights is None:
#         # If no weights provided, this simply calls `np.percentile`.
#         return np.percentile(x, list(100.0 * q))
#     else:
#         # If weights are provided, compute the weighted quantiles.
#         weights = np.atleast_1d(weights)
#         if len(x) != len(weights):
#             raise ValueError("Dimension mismatch: len(weights) != len(x).")
#         idx = np.argsort(x)  # sort samples
#         sw = weights[idx]  # sort weights
#         cdf = np.cumsum(sw)[:-1]  # compute CDF
#         cdf /= cdf[-1]  # normalize CDF
#         cdf = np.append(0, cdf)  # ensure proper span
#         quantiles = np.interp(q, cdf, x[idx]).tolist()
#         return quantiles
# 
# Path: prospect/models/priors.py
# class TopHat(Uniform):
#     """Uniform distribution between two bounds, renamed for backwards compatibility
#     :param mini:
#         Minimum of the distribution
# 
#     :param maxi:
#         Maximum of the distribution
#     """


import numpy as np
from .corner import _quantile
from ..models.priors import TopHat as Uniform
    from matplotlib.patches import Rectangle
    from matplotlib.collections import PatchCollection
           "boxplot", "violinplot", "step"]


def get_simple_prior(prior, xlim, num=1000):
    xx = np.linspace(*xlim, num=num)
    px = np.array([prior(x) for x in xx])
    px = np.exp(px)
    return xx, px / px.max()


def sample_prior(model, nsample=1e6):
    """Generate samples from the prior.

    :param model:
        A ProspectorParams instance.

    :param nsample: (int, optional, default: 1000000)
        Number of samples to take

    :returns samples: ndarray of shape(nsample, ndim)
        Samples from the prior

    :returns labels: list of strings
        The names of the free parameters.
    """
    labels = model.free_params
    chain = np.zeros([nsample, model.ndim])
    #chain = []
    for l in labels:
        prior = model.config_dict[l]["prior"]

# Path: prospect/plotting/corner.py
# def _quantile(x, q, weights=None):
#     """Compute (weighted) quantiles from an input set of samples.
# 
#     Parameters
#     ----------
#     x : `~numpy.ndarray` with shape (nsamps,)
#         Input samples.
# 
#     q : `~numpy.ndarray` with shape (nquantiles,)
#        The list of quantiles to compute from `[0., 1.]`.
# 
#     weights : `~numpy.ndarray` with shape (nsamps,), optional
#         The associated weight from each sample.
# 
#     Returns
#     -------
#     quantiles : `~numpy.ndarray` with shape (nquantiles,)
#         The weighted sample quantiles computed at `q`.
# 
#     """
#     # Initial check.
#     x = np.atleast_1d(x)
#     q = np.atleast_1d(q)
# 
#     # Quantile check.
#     if np.any(q < 0.0) or np.any(q > 1.0):
#         raise ValueError("Quantiles must be between 0. and 1.")
# 
#     if weights is None:
#         # If no weights provided, this simply calls `np.percentile`.
#         return np.percentile(x, list(100.0 * q))
#     else:
#         # If weights are provided, compute the weighted quantiles.
#         weights = np.atleast_1d(weights)
#         if len(x) != len(weights):
#             raise ValueError("Dimension mismatch: len(weights) != len(x).")
#         idx = np.argsort(x)  # sort samples
#         sw = weights[idx]  # sort weights
#         cdf = np.cumsum(sw)[:-1]  # compute CDF
#         cdf /= cdf[-1]  # normalize CDF
#         cdf = np.append(0, cdf)  # ensure proper span
#         quantiles = np.interp(q, cdf, x[idx]).tolist()
#         return quantiles
# 
# Path: prospect/models/priors.py
# class TopHat(Uniform):
#     """Uniform distribution between two bounds, renamed for backwards compatibility
#     :param mini:
#         Minimum of the distribution
# 
#     :param maxi:
#         Maximum of the distribution
#     """


# Path: prospect/plotting/utils.py
import numpy as np
from .corner import _quantile
from ..models.priors import TopHat as Uniform
    from matplotlib.patches import Rectangle
    from matplotlib.collections import PatchCollection

           "boxplot", "violinplot", "step"]


def get_simple_prior(prior, xlim, num=1000):
    xx = np.linspace(*xlim, num=num)
    px = np.array([prior(x) for x in xx])
    px = np.exp(px)
    return xx, px / px.max()


def sample_prior(model, nsample=1e6):
    """Generate samples from the prior.

    :param model:
        A ProspectorParams instance.

    :param nsample: (int, optional, default: 1000000)
        Number of samples to take

    :returns samples: ndarray of shape(nsample, ndim)
        Samples from the prior

    :returns labels: list of strings
        The names of the free parameters.
    """
    labels = model.free_params
    chain = np.zeros([nsample, model.ndim])
    #chain = []
    for l in labels:
        prior = model.config_dict[l]["prior"]

        if isinstance(prior, Uniform):