# 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
        sig = np.array(sig)
        xx, yy = np.meshgrid(test_times, times, copy=False, indexing='xy')
        ax.contour(xx, yy, sig, colors='black', levels=[0],
                   linestyles='dotted')
    ax.axhline(0, color='k')
    ax.axvline(0, color='k')
    if colorbar:
        pretty_colorbar(
            im, ax=ax, ticks=[vmin, chance, vmax],
            ticklabels=['%.2f' % vmin, 'Chance', '%.2f' % vmax])

    #
    if diagonal is not None:
        ax.plot([np.max([min(times), min(test_times)]),
                 np.min([max(times), max(test_times)])],
                [np.max([min(times), min(test_times)]),
                 np.min([max(times), max(test_times)])], color=diagonal)
    # setup ticks
    xticks, xticklabels = _set_ticks(test_times)
    ax.set_xticks(xticks)
    ax.set_xticklabels(xticklabels)
    yticks, yticklabels = _set_ticks(times)
    ax.set_yticks(yticks)
    ax.set_yticklabels(yticklabels)
    if len(xlabel):
        ax.set_xlabel(xlabel)
    if len(ylabel):
        ax.set_ylabel(ylabel)
    ax.set_xlim(min(test_times), max(test_times))
    ax.set_ylim(min(times), max(times))

# 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

        sig = np.array(sig)
        xx, yy = np.meshgrid(test_times, times, copy=False, indexing='xy')
        ax.contour(xx, yy, sig, colors='black', levels=[0],
                   linestyles='dotted')
    ax.axhline(0, color='k')
    ax.axvline(0, color='k')
    if colorbar:
        pretty_colorbar(
            im, ax=ax, ticks=[vmin, chance, vmax],
            ticklabels=['%.2f' % vmin, 'Chance', '%.2f' % vmax])

    #
    if diagonal is not None:
        ax.plot([np.max([min(times), min(test_times)]),
                 np.min([max(times), max(test_times)])],
                [np.max([min(times), min(test_times)]),
                 np.min([max(times), max(test_times)])], color=diagonal)
    # setup ticks
    xticks, xticklabels = _set_ticks(test_times)
    ax.set_xticks(xticks)
    ax.set_xticklabels(xticklabels)
    yticks, yticklabels = _set_ticks(times)
    ax.set_yticks(yticks)
    ax.set_yticklabels(yticklabels)
    if len(xlabel):
        ax.set_xlabel(xlabel)
    if len(ylabel):
        ax.set_ylabel(ylabel)
    ax.set_xlim(min(test_times), max(test_times))
    ax.set_ylim(min(times), max(times))

    pretty_plot(ax)