# Buggy code
def _set_psd_plot_params(info, proj, picks, ax, area_mode):
    """Set PSD plot params."""
    import matplotlib.pyplot as plt

    if area_mode not in [None, "std", "range"]:
        raise ValueError('"area_mode" must be "std", "range", or None')
    if picks is None:
        # XXX this could be refactored more with e.g., plot_evoked
        megs = ["mag", "grad", False, False, False]
        eegs = [False, False, True, False, False]
        seegs = [False, False, False, True, False]
        ecogs = [False, False, False, False, True]
        names = ["mag", "grad", "eeg", "seeg", "ecog"]
        titles = _handle_default("titles", None)
        units = _handle_default("units", None)
        scalings = _handle_default("scalings", None)
        picks_list = list()
        titles_list = list()
        units_list = list()
        scalings_list = list()
        for meg, eeg, seeg, ecog, name in zip(megs, eegs, seegs, ecogs, names):
            picks = pick_types(
                info, meg=meg, eeg=eeg, seeg=seeg, ecog=ecog, ref_meg=False
            )
            if len(picks) > 0:
                picks_list.append(picks)
                titles_list.append(titles[name])
                units_list.append(units[name])
                scalings_list.append(scalings[name])
        if len(picks_list) == 0:
            raise RuntimeError("No data channels found")
        if ax is not None:
            if isinstance(ax, plt.Axes):
                ax = [ax]
            if len(ax) != len(picks_list):
                raise ValueError(
                    "For this dataset with picks=None %s axes "
                    "must be supplied, got %s" % (len(picks_list), len(ax))
                )
            ax_list = ax
    else:
        picks_list = [picks]
        titles_list = ["Selected channels"]
        units_list = ["amplitude"]
        scalings_list = [1.0]
        ax_list = [ax]

    make_label = False
    fig = None
    if ax is None:
        fig = plt.figure()
        ax_list = list()
        for ii in range(len(picks_list)):
            # Make x-axes change together
            if ii > 0:
                ax_list.append(
                    plt.subplot(len(picks_list), 1, ii + 1, sharex=ax_list[0])
                )
            else:
                ax_list.append(plt.subplot(len(picks_list), 1, ii + 1))
        make_label = True
    else:
        fig = ax_list[0].get_figure()

    return (
        fig,
        picks_list,
        titles_list,
        units_list,
        scalings_list,
        ax_list,
        make_label,
    )


# Traceback (IndexError)
/miniconda3/envs/mne/lib/python2.7/site-packages/mne/viz/evoked.py:433: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 2
for ax in np.array(axes)[selectables]:
Traceback (most recent call last):
File "psd_bug.py", line 10, in <module>
ax = raw.plot_psd(picks=picks, dB=False, show=True, average=False)
File "<string>", line 2, in plot_psd
File "/home/erik/miniconda3/envs/mne/lib/python2.7/site-packages/mne/utils.py", line 728, in verbose
return function(*args, **kwargs)
File "/home/erik/miniconda3/envs/mne/lib/python2.7/site-packages/mne/io/base.py", line 1779, in plot_psd
xscale=xscale, reject_by_annotation=reject_by_annotation)
File "<string>", line 2, in plot_raw_psd
File "/home/erik/miniconda3/envs/mne/lib/python2.7/site-packages/mne/utils.py", line 728, in verbose
return function(*args, **kwargs)
File "/home/erik/miniconda3/envs/mne/lib/python2.7/site-packages/mne/viz/raw.py", line 812, in plot_raw_psd
line_alpha=line_alpha)
File "/home/erik/miniconda3/envs/mne/lib/python2.7/site-packages/mne/viz/evoked.py", line 433, in _plot_lines
for ax in np.array(axes)[selectables]:
IndexError: index 1 is out of bounds for axis 1 with size 1

# Fixed code
def _set_psd_plot_params(info, proj, picks, ax, area_mode):
    """Set PSD plot params."""
    import matplotlib.pyplot as plt

    if area_mode not in [None, "std", "range"]:
        raise ValueError('"area_mode" must be "std", "range", or None')

    # XXX this could be refactored more with e.g., plot_evoked
    megs = ["mag", "grad", False, False, False]
    eegs = [False, False, True, False, False]
    seegs = [False, False, False, True, False]
    ecogs = [False, False, False, False, True]
    names = ["mag", "grad", "eeg", "seeg", "ecog"]
    titles = _handle_default("titles", None)
    units = _handle_default("units", None)
    scalings = _handle_default("scalings", None)
    picks_list = list()
    titles_list = list()
    units_list = list()
    scalings_list = list()
    for meg, eeg, seeg, ecog, name in zip(megs, eegs, seegs, ecogs, names):
        these_picks = pick_types(
            info, meg=meg, eeg=eeg, seeg=seeg, ecog=ecog, ref_meg=False
        )
        if picks is not None:
            these_picks = np.intersect1d(these_picks, picks)
        if len(these_picks) > 0:
            picks_list.append(these_picks)
            titles_list.append(titles[name])
            units_list.append(units[name])
            scalings_list.append(scalings[name])
    if len(picks_list) == 0:
        raise RuntimeError("No data channels found")
    if ax is not None:
        if isinstance(ax, plt.Axes):
            ax = [ax]
        if len(ax) != len(picks_list):
            raise ValueError(
                "For this dataset with picks=None %s axes "
                "must be supplied, got %s" % (len(picks_list), len(ax))
            )
        ax_list = ax
    del picks

    make_label = False
    fig = None
    if ax is None:
        fig = plt.figure()
        ax_list = list()
        for ii in range(len(picks_list)):
            # Make x-axes change together
            if ii > 0:
                ax_list.append(
                    plt.subplot(len(picks_list), 1, ii + 1, sharex=ax_list[0])
                )
            else:
                ax_list.append(plt.subplot(len(picks_list), 1, ii + 1))
        make_label = True
    else:
        fig = ax_list[0].get_figure()

    return (
        fig,
        picks_list,
        titles_list,
        units_list,
        scalings_list,
        ax_list,
        make_label,
    )