# Path: jr/plot/base.py
# def pretty_plot(ax=None):
#     if ax is None:
#         plt.gca()
#     ax.tick_params(colors='dimgray')
#     ax.xaxis.label.set_color('dimgray')
#     ax.yaxis.label.set_color('dimgray')
#     try:
#         ax.zaxis.label.set_color('dimgray')
#     except AttributeError:
#         pass
#     try:
#         ax.xaxis.set_ticks_position('bottom')
#         ax.yaxis.set_ticks_position('left')
#     except ValueError:
#         pass
#     ax.spines['left'].set_color('dimgray')
#     ax.spines['bottom'].set_color('dimgray')
#     ax.spines['right'].set_visible(False)
#     ax.spines['top'].set_visible(False)
#     return ax
# 
# 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)
#     else:
#         m = np.nanmean(y, axis=0)
#         std = np.nanstd(y, axis=0)
#     n = y.shape[0] - np.sum(np.isnan(y), axis=0)
# 
#     return plot_eb(x, m, std / np.sqrt(n), **kwargs)
# 
# def plot_widths(xs, ys, widths, ax=None, color='b', xlim=None, ylim=None,
#                 **kwargs):
#     xs, ys, widths = np.array(xs), np.array(ys), np.array(widths)
#     if not (len(xs) == len(ys) == len(widths)):
#         raise ValueError('xs, ys, and widths must have identical lengths')
#     fig = None
#     if ax is None:
#         fig, ax = plt.subplots(1)
# 
#     segmentx, segmenty = [xs[0]], [ys[0]]
#     current_width = widths[0]
#     for ii, (x, y, width) in enumerate(zip(xs, ys, widths)):
#         segmentx.append(x)
#         segmenty.append(y)
#         if (width != current_width) or (ii == (len(xs) - 1)):
#             ax.plot(segmentx, segmenty, linewidth=current_width, color=color,
#                     **kwargs)
#             segmentx, segmenty = [x], [y]
#             current_width = width
#     if xlim is None:
#         xlim = [min(xs), max(xs)]
#     if ylim is None:
#         ylim = [min(ys), max(ys)]
#     ax.set_xlim(xlim)
#     ax.set_ylim(ylim)
# 
#     return ax if fig is None else fig
# 
# def pretty_colorbar(im=None, ax=None, ticks=None, ticklabels=None, nticks=3,
#                     **kwargs):
#     if ax is None:
#         ax = plt.gca()
#     if im is None:
#         for obj in ax.get_children():
#             if isinstance(obj, matplotlib.image.AxesImage):
#                 im = obj
#                 continue
#         if im is None:
#             raise RuntimeError('did not find the image')
#     if ticks is None:
#         clim = im.get_clim()
#         # XXX bug https://github.com/matplotlib/matplotlib/issues/6352
#         if None in clim:
#             fig = ax.get_figure()
#             fig.canvas.draw()
#             clim = im.get_clim()
#         ticks = np.linspace(clim[0], clim[1], nticks)
#     cb = plt.colorbar(im, ax=ax, ticks=ticks, **kwargs)
#     if ticklabels is None:
#         ticklabels = ['%.2f' % ii for ii in ticks]
#     cb.ax.set_yticklabels(ticklabels, color='dimgray')
#     cb.ax.xaxis.label.set_color('dimgray')
#     cb.ax.yaxis.label.set_color('dimgray')
#     cb.ax.spines['left'].set_color('dimgray')
#     cb.ax.spines['right'].set_color('dimgray')
#     box = cb.ax.get_children()[2]
#     box.set_edgecolor('dimgray')
#     return cb


import matplotlib.pyplot as plt
import numpy as np
from .base import pretty_plot, plot_sem, plot_widths, pretty_colorbar

    if (scores.ndim == 1) or (scores.shape[1] <= 1):
        scores = scores[:, None].T
    if times is None:
        times = np.arange(scores.shape[1]) / float(sfreq)

    # setup plot
    if ax is None:
        ax = plt.gca()

    # Plot SEM
    if scores.ndim == 2:
        scores_m = np.nanmean(scores, axis=0)
        n = len(scores)
        n -= sum(np.isnan(np.mean(scores, axis=1)))
        sem = np.nanstd(scores, axis=0) / np.sqrt(n)
        plot_sem(times, scores, color=color, ax=ax)
    else:
        scores_m = scores
        sem = np.zeros_like(scores_m)

    # Plot significance
    if sig is not None:
        sig = np.squeeze(sig)
        widths = width * sig
        if fill:
            scores_sig = (chance + (scores_m - chance) * sig)
            ax.fill_between(times, chance, scores_sig, color=color,
                            alpha=alpha, linewidth=0)
            ax.plot(times, scores_m, color='k')

# Path: jr/plot/base.py
# def pretty_plot(ax=None):
#     if ax is None:
#         plt.gca()
#     ax.tick_params(colors='dimgray')
#     ax.xaxis.label.set_color('dimgray')
#     ax.yaxis.label.set_color('dimgray')
#     try:
#         ax.zaxis.label.set_color('dimgray')
#     except AttributeError:
#         pass
#     try:
#         ax.xaxis.set_ticks_position('bottom')
#         ax.yaxis.set_ticks_position('left')
#     except ValueError:
#         pass
#     ax.spines['left'].set_color('dimgray')
#     ax.spines['bottom'].set_color('dimgray')
#     ax.spines['right'].set_visible(False)
#     ax.spines['top'].set_visible(False)
#     return ax
# 
# 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)
#     else:
#         m = np.nanmean(y, axis=0)
#         std = np.nanstd(y, axis=0)
#     n = y.shape[0] - np.sum(np.isnan(y), axis=0)
# 
#     return plot_eb(x, m, std / np.sqrt(n), **kwargs)
# 
# def plot_widths(xs, ys, widths, ax=None, color='b', xlim=None, ylim=None,
#                 **kwargs):
#     xs, ys, widths = np.array(xs), np.array(ys), np.array(widths)
#     if not (len(xs) == len(ys) == len(widths)):
#         raise ValueError('xs, ys, and widths must have identical lengths')
#     fig = None
#     if ax is None:
#         fig, ax = plt.subplots(1)
# 
#     segmentx, segmenty = [xs[0]], [ys[0]]
#     current_width = widths[0]
#     for ii, (x, y, width) in enumerate(zip(xs, ys, widths)):
#         segmentx.append(x)
#         segmenty.append(y)
#         if (width != current_width) or (ii == (len(xs) - 1)):
#             ax.plot(segmentx, segmenty, linewidth=current_width, color=color,
#                     **kwargs)
#             segmentx, segmenty = [x], [y]
#             current_width = width
#     if xlim is None:
#         xlim = [min(xs), max(xs)]
#     if ylim is None:
#         ylim = [min(ys), max(ys)]
#     ax.set_xlim(xlim)
#     ax.set_ylim(ylim)
# 
#     return ax if fig is None else fig
# 
# def pretty_colorbar(im=None, ax=None, ticks=None, ticklabels=None, nticks=3,
#                     **kwargs):
#     if ax is None:
#         ax = plt.gca()
#     if im is None:
#         for obj in ax.get_children():
#             if isinstance(obj, matplotlib.image.AxesImage):
#                 im = obj
#                 continue
#         if im is None:
#             raise RuntimeError('did not find the image')
#     if ticks is None:
#         clim = im.get_clim()
#         # XXX bug https://github.com/matplotlib/matplotlib/issues/6352
#         if None in clim:
#             fig = ax.get_figure()
#             fig.canvas.draw()
#             clim = im.get_clim()
#         ticks = np.linspace(clim[0], clim[1], nticks)
#     cb = plt.colorbar(im, ax=ax, ticks=ticks, **kwargs)
#     if ticklabels is None:
#         ticklabels = ['%.2f' % ii for ii in ticks]
#     cb.ax.set_yticklabels(ticklabels, color='dimgray')
#     cb.ax.xaxis.label.set_color('dimgray')
#     cb.ax.yaxis.label.set_color('dimgray')
#     cb.ax.spines['left'].set_color('dimgray')
#     cb.ax.spines['right'].set_color('dimgray')
#     box = cb.ax.get_children()[2]
#     box.set_edgecolor('dimgray')
#     return cb


# Path: jr/plot/gat_plot.py
import matplotlib.pyplot as plt
import numpy as np
from .base import pretty_plot, plot_sem, plot_widths, pretty_colorbar


    if (scores.ndim == 1) or (scores.shape[1] <= 1):
        scores = scores[:, None].T
    if times is None:
        times = np.arange(scores.shape[1]) / float(sfreq)

    # setup plot
    if ax is None:
        ax = plt.gca()

    # Plot SEM
    if scores.ndim == 2:
        scores_m = np.nanmean(scores, axis=0)
        n = len(scores)
        n -= sum(np.isnan(np.mean(scores, axis=1)))
        sem = np.nanstd(scores, axis=0) / np.sqrt(n)
        plot_sem(times, scores, color=color, ax=ax)
    else:
        scores_m = scores
        sem = np.zeros_like(scores_m)

    # Plot significance
    if sig is not None:
        sig = np.squeeze(sig)
        widths = width * sig
        if fill:
            scores_sig = (chance + (scores_m - chance) * sig)
            ax.fill_between(times, chance, scores_sig, color=color,
                            alpha=alpha, linewidth=0)
            ax.plot(times, scores_m, color='k')

            plot_widths(times, scores_m, widths, ax=ax, color='k')