# 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


import matplotlib.pyplot as plt
import numpy as np
from . import pretty_plot
    from mne import pick_types
    from mne import pick_types

def plot_butterfly(evoked, ax=None, sig=None, color=None, ch_type=None):
    if ch_type is not None:
        picks = pick_types(evoked.info, ch_type)
        evoked = evoked.copy()
        evoked = evoked.pick_types(ch_type)
        sig = sig[picks, :] if sig is not None else None
    times = evoked.times * 1e3
    data = evoked.data
    ax = plt.gca() if ax is None else ax
    ax.plot(times, data.T, color='k', alpha=.5)
    gfp = np.vstack((data.max(0), data.min(0)))
    if sig is not None:
        sig = np.array(np.sum(sig, axis=0) > 0., dtype=int)
        ax.fill_between(np.hstack((times, times[::-1])),
                        np.hstack((sig * gfp[0, :] + (1 - sig) * gfp[1, :],
                                   gfp[1, ::-1])),
                        facecolor=color, edgecolor='none', alpha=.5,
                        zorder=len(data) + 1)
    ax.axvline(0, color='k')
    ax.set_xlabel('Times (ms)')
    ax.set_xlim(min(times), max(times))
    xticks = np.arange(np.ceil(min(times)/1e2) * 1e2,
                       np.floor(max(times)/1e2) * 1e2 + 1e-10, 100)
    ax.set_xticks(xticks)
    ax.set_xticklabels(['%i' % t if t in [xticks[0], xticks[-1], 0]
                        else '' for t in xticks])
    ax.set_yticks([np.min(data), np.max(data)])
    ax.set_ylim(np.min(data), np.max(data))
    ax.set_xlim(np.min(times), np.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


# Path: jr/plot/meg.py
import matplotlib.pyplot as plt
import numpy as np
from . import pretty_plot
    from mne import pick_types
    from mne import pick_types


def plot_butterfly(evoked, ax=None, sig=None, color=None, ch_type=None):
    if ch_type is not None:
        picks = pick_types(evoked.info, ch_type)
        evoked = evoked.copy()
        evoked = evoked.pick_types(ch_type)
        sig = sig[picks, :] if sig is not None else None
    times = evoked.times * 1e3
    data = evoked.data
    ax = plt.gca() if ax is None else ax
    ax.plot(times, data.T, color='k', alpha=.5)
    gfp = np.vstack((data.max(0), data.min(0)))
    if sig is not None:
        sig = np.array(np.sum(sig, axis=0) > 0., dtype=int)
        ax.fill_between(np.hstack((times, times[::-1])),
                        np.hstack((sig * gfp[0, :] + (1 - sig) * gfp[1, :],
                                   gfp[1, ::-1])),
                        facecolor=color, edgecolor='none', alpha=.5,
                        zorder=len(data) + 1)
    ax.axvline(0, color='k')
    ax.set_xlabel('Times (ms)')
    ax.set_xlim(min(times), max(times))
    xticks = np.arange(np.ceil(min(times)/1e2) * 1e2,
                       np.floor(max(times)/1e2) * 1e2 + 1e-10, 100)
    ax.set_xticks(xticks)
    ax.set_xticklabels(['%i' % t if t in [xticks[0], xticks[-1], 0]
                        else '' for t in xticks])
    ax.set_yticks([np.min(data), np.max(data)])
    ax.set_ylim(np.min(data), np.max(data))
    ax.set_xlim(np.min(times), np.max(times))

    pretty_plot(ax)