Repository: mne-tools/mne-python

Issue:
`vlines='auto' in mne.viz.plot_compare_evokeds doesn't work
I got error 
vlines must be a list or tuple, not <class 'str'>

`conditions = ['1', '2', '4']
evoked_dict = dict()
for condition in conditions:
    evoked_dict[condition] = mne.read_evokeds(fname, baseline=(None, 0), proj=True, condition=condition)
print(evoked_dict)

colors = dict(Left="Crimson", Right="CornFlowerBlue")

pick = evoked_dict['1'].ch_names.index('MEG0242')

mne.viz.plot_compare_evokeds(evoked_dict, picks=pick, colors=colors, vlines='auto', split_legend=True)`

tmin= 0.0
tmax = 1.021


Discussion:

Resolving patch:
diff --git a/mne/viz/evoked.py b/mne/viz/evoked.py
--- a/mne/viz/evoked.py
+++ b/mne/viz/evoked.py
@@ -1862,8 +1862,8 @@ def plot_compare_evokeds(evokeds, picks=None, gfp=False, colors=None,
     info = one_evoked.info
     tmin, tmax = times[0], times[-1]
 
-    if vlines == "auto" and (tmin < 0 and tmax > 0):
-        vlines = [0.]
+    if vlines == "auto":
+        vlines = [0.] if (tmin < 0 < tmax) else []
     _validate_type(vlines, (list, tuple), "vlines", "list or tuple")
 
     picks = [] if picks is None else picks
diff --git a/mne/viz/utils.py b/mne/viz/utils.py
--- a/mne/viz/utils.py
+++ b/mne/viz/utils.py
@@ -2316,6 +2316,8 @@ def _setup_ax_spines(axes, vlines, tmin, tmax, invert_y=False,
     xticks = sorted(list(set([x for x in axes.get_xticks()] + vlines)))
     axes.set_xticks(xticks)
     x_extrema = [t for t in xticks if tmax >= t >= tmin]
+    if len(x_extrema) == 0:  # can happen with one time point
+        x_extrema = [tmin, tmax]
     if truncate_xaxis is True:
         axes.spines['bottom'].set_bounds(x_extrema[0], x_extrema[-1])
     else:
@@ -2328,7 +2330,8 @@ def _setup_ax_spines(axes, vlines, tmin, tmax, invert_y=False,
     if invert_y:
         axes.invert_yaxis()
     axes.spines['right'].set_color('none')
-    axes.set_xlim(tmin, tmax)
+    if tmin != tmax:
+        axes.set_xlim(tmin, tmax)
     if truncate_xaxis is False:
         axes.axis("tight")
         axes.set_autoscale_on(False)


Test patch:
diff --git a/mne/viz/tests/test_evoked.py b/mne/viz/tests/test_evoked.py
--- a/mne/viz/tests/test_evoked.py
+++ b/mne/viz/tests/test_evoked.py
@@ -293,6 +293,7 @@ def test_plot_compare_evokeds():
                          ylim=dict(mag=(1, 10)), ci=_parametric_ci,
                          truncate_yaxis='max_ticks', show_sensors=False,
                          show_legend=False)
+    plt.close('all')
 
     # sequential colors
     evokeds = (evoked, blue, red)
@@ -318,10 +319,20 @@ def test_plot_compare_evokeds():
     plot_compare_evokeds([red, blue], picks=[0], cmap="summer", ci=None,
                          split_legend=None)
     plot_compare_evokeds([red, blue], cmap=None, split_legend=True)
-    pytest.raises(ValueError, plot_compare_evokeds, [red] * 20)
-    pytest.raises(ValueError, plot_compare_evokeds, contrasts,
-                  cmap='summer')
+    with pytest.raises(ValueError, match='more than [1-9]'):
+        plot_compare_evokeds([red] * 20)
+    with pytest.raises(ValueError, match='must specify the colors'):
+        plot_compare_evokeds(contrasts, cmap='summer')
+    plt.close('all')
 
+    # smoke test for tmin >= 0 (from mailing list)
+    red.crop(0.01, None)
+    assert len(red.times) > 2
+    plot_compare_evokeds(red)
+    # smoke test for one time point (not useful but should not fail)
+    red.crop(0.01, 0.01)
+    assert len(red.times) == 1
+    plot_compare_evokeds(red)
     plt.close('all')
 
 
diff --git a/mne/viz/tests/test_topo.py b/mne/viz/tests/test_topo.py
--- a/mne/viz/tests/test_topo.py
+++ b/mne/viz/tests/test_topo.py
@@ -70,13 +70,9 @@ def _get_epochs_delayed_ssp():
     return epochs_delayed_ssp
 
 
-def test_plot_topo():
-    """Test plotting of ERP topography."""
-    # Show topography
+def test_plot_joint():
+    """Test joint plot."""
     evoked = _get_epochs().average()
-    # should auto-find layout
-    plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w')
-    # Test jointplot
     evoked.plot_joint(ts_args=dict(time_unit='s'),
                       topomap_args=dict(time_unit='s'))
 
@@ -92,9 +88,18 @@ def return_inds(d):  # to test function kwarg to zorder arg of evoked.plot
     axes = plt.subplots(nrows=3)[-1].flatten().tolist()
     evoked.plot_joint(times=[0], picks=[6, 7, 8],  ts_args=dict(axes=axes[0]),
                       topomap_args={"axes": axes[1:], "time_unit": "s"})
-    plt.close()
-    pytest.raises(ValueError, evoked.plot_joint, picks=[6, 7, 8],
-                  ts_args=dict(axes=axes[0]), topomap_args=dict(axes=axes[2:]))
+    with pytest.raises(ValueError, match='array of length 6'):
+        evoked.plot_joint(picks=[6, 7, 8], ts_args=dict(axes=axes[0]),
+                          topomap_args=dict(axes=axes[2:]))
+    plt.close('all')
+
+
+def test_plot_topo():
+    """Test plotting of ERP topography."""
+    # Show topography
+    evoked = _get_epochs().average()
+    # should auto-find layout
+    plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w')
 
     picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3])
     picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True)