# Path: jr/utils.py
# def logcenter(center, x=None, inverse=False):
#     # Authors: Jean-Remi King, <jeanremi.king@gmail.com>
#     #          Clement Levrard <clement.levrard@gmail.com>
#     #
#     # License: BSD (3-clause)
#     """
#     Creates a logarithmic scale centered around center, and bounded between
#     [0., 1.] such that:
#         f(0, center) = 0
#         f(1, center) = 1
#         f(center, center) = .5
# 
#     Parameters
#     ----------
#         x : float | np.array | None
#             If float or np.array, 0. < x < 1.
#             If None, set to np.linspace(0., 1., 256).
#             Defaults to None.
#         center : float
#             0. < center < 1.
#     Returns
#     -------
#         y : float | np.array
#     """
# 
#     from numpy import exp, log
#     if x is None:
#         x = np.linspace(0., 1., 256)
#     if center >= 1. or center <= 0.:
#         raise ValueError('center must be between 0 and 1')
#     if center == .5:
#         y = x
#     else:
#         n = 1. / center
#         if inverse is False:
#             y = (exp(2 * log(n - 1) * x) - 1) / (n * (n - 2))
#         else:
#             y = log(x * (n * (n - 2)) + 1) / (2 * log(n - 1))
#     if center > .5:
#         y = 1. - y
#     return y
# 
# Path: jr/stats/base.py
# def median_abs_deviation(x, axis=None):
#     """median absolute deviation"""
#     x = np.asarray(x)
#     # transpose selected axis in front
#     shape = x.shape
#     n_dim = len(shape)
#     axis_ = None
#     if axis is not None:
#         dim_order = np.hstack((axis, np.delete(np.arange(n_dim), axis)))
#         x = np.transpose(x, dim_order)
#         axis_ = 0
# 
#     # compute median
#     center = np.median(x, axis=axis_, keepdims=False)
#     if len(center):
#         center = center[np.newaxis, ...]
# 
#     # compute median absolute deviation from median
#     mad = np.median(np.abs(x - center), axis=axis_)
# 
#     return mad


import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.colors as col
    import itertools
from matplotlib.colors import LinearSegmentedColormap
from ..utils import logcenter
from ..stats import median_abs_deviation
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    return ax if fig is None else fig


def plot_sem(x, y, robust=False, **kwargs):
    """
    Parameters
    ----------
    x : list | np.array()
    y : list | np.array()
    robust : bool
        If False use mean + std,
        If True median + mad
    ax
    alpha
    color
    line_args
    err_args

    Returns
    -------
    ax

    Adapted from http://tonysyu.github.io/plotting-error-bars.html#.VRE9msvmvEU
    """
    x, y = np.array(x), np.array(y)
    if robust:
        m = np.nanmedian(y, axis=0)

# Path: jr/utils.py
# def logcenter(center, x=None, inverse=False):
#     # Authors: Jean-Remi King, <jeanremi.king@gmail.com>
#     #          Clement Levrard <clement.levrard@gmail.com>
#     #
#     # License: BSD (3-clause)
#     """
#     Creates a logarithmic scale centered around center, and bounded between
#     [0., 1.] such that:
#         f(0, center) = 0
#         f(1, center) = 1
#         f(center, center) = .5
# 
#     Parameters
#     ----------
#         x : float | np.array | None
#             If float or np.array, 0. < x < 1.
#             If None, set to np.linspace(0., 1., 256).
#             Defaults to None.
#         center : float
#             0. < center < 1.
#     Returns
#     -------
#         y : float | np.array
#     """
# 
#     from numpy import exp, log
#     if x is None:
#         x = np.linspace(0., 1., 256)
#     if center >= 1. or center <= 0.:
#         raise ValueError('center must be between 0 and 1')
#     if center == .5:
#         y = x
#     else:
#         n = 1. / center
#         if inverse is False:
#             y = (exp(2 * log(n - 1) * x) - 1) / (n * (n - 2))
#         else:
#             y = log(x * (n * (n - 2)) + 1) / (2 * log(n - 1))
#     if center > .5:
#         y = 1. - y
#     return y
# 
# Path: jr/stats/base.py
# def median_abs_deviation(x, axis=None):
#     """median absolute deviation"""
#     x = np.asarray(x)
#     # transpose selected axis in front
#     shape = x.shape
#     n_dim = len(shape)
#     axis_ = None
#     if axis is not None:
#         dim_order = np.hstack((axis, np.delete(np.arange(n_dim), axis)))
#         x = np.transpose(x, dim_order)
#         axis_ = 0
# 
#     # compute median
#     center = np.median(x, axis=axis_, keepdims=False)
#     if len(center):
#         center = center[np.newaxis, ...]
# 
#     # compute median absolute deviation from median
#     mad = np.median(np.abs(x - center), axis=axis_)
# 
#     return mad


# Path: jr/plot/base.py
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.colors as col
    import itertools
from matplotlib.colors import LinearSegmentedColormap
from ..utils import logcenter
from ..stats import median_abs_deviation

    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    return ax if fig is None else fig


def plot_sem(x, y, robust=False, **kwargs):
    """
    Parameters
    ----------
    x : list | np.array()
    y : list | np.array()
    robust : bool
        If False use mean + std,
        If True median + mad
    ax
    alpha
    color
    line_args
    err_args

    Returns
    -------
    ax

    Adapted from http://tonysyu.github.io/plotting-error-bars.html#.VRE9msvmvEU
    """
    x, y = np.array(x), np.array(y)
    if robust:
        m = np.nanmedian(y, axis=0)

        std = median_abs_deviation(y, axis=0)