Repository: mne-tools/mne-python

Issue:
Problem with the plot_read_noise_covariance_matrix example
It seems as though this example isn't being rendered properly

http://martinos.org/mne/dev/auto_examples/plot_read_noise_covariance_matrix.html



Discussion:

Resolving patch:
diff --git a/examples/plot_read_noise_covariance_matrix.py b/examples/plot_read_noise_covariance_matrix.py
--- a/examples/plot_read_noise_covariance_matrix.py
+++ b/examples/plot_read_noise_covariance_matrix.py
@@ -9,23 +9,21 @@
 #
 # License: BSD (3-clause)
 
+from os import path as op
 import mne
 from mne.datasets import sample
-import matplotlib.pyplot as plt
 
 print(__doc__)
 
 data_path = sample.data_path()
-fname = data_path + '/MEG/sample/sample_audvis-cov.fif'
+fname_cov = op.join(data_path, 'MEG', 'sample', 'sample_audvis-cov.fif')
+fname_evo = op.join(data_path, 'MEG', 'sample', 'sample_audvis-ave.fif')
 
-cov = mne.Covariance(fname)
+cov = mne.read_cov(fname_cov)
 print(cov)
+evoked = mne.read_evokeds(fname_evo)[0]
 
 ###############################################################################
 # Show covariance
 
-# Note: if you have the measurement info you can use mne.viz.plot_cov
-
-plt.matshow(cov.data, cmap='RdBu_r')
-plt.title('Noise covariance matrix (%d channels)' % cov.data.shape[0])
-plt.show()
+cov.plot(evoked.info, exclude='bads', show_svd=False)
diff --git a/mne/cov.py b/mne/cov.py
--- a/mne/cov.py
+++ b/mne/cov.py
@@ -173,6 +173,40 @@ def __iadd__(self, cov):
 
         return self
 
+    @verbose
+    def plot(self, info, exclude=[], colorbar=True, proj=False, show_svd=True,
+             show=True, verbose=None):
+        """Plot Covariance data
+
+        Parameters
+        ----------
+        info: dict
+            Measurement info.
+        exclude : list of string | str
+            List of channels to exclude. If empty do not exclude any channel.
+            If 'bads', exclude info['bads'].
+        colorbar : bool
+            Show colorbar or not.
+        proj : bool
+            Apply projections or not.
+        show : bool
+            Call pyplot.show() as the end or not.
+        show_svd : bool
+            Plot also singular values of the noise covariance for each sensor
+            type. We show square roots ie. standard deviations.
+        verbose : bool, str, int, or None
+            If not None, override default verbose level (see mne.verbose).
+
+        Returns
+        -------
+        fig_cov : instance of matplotlib.pyplot.Figure
+            The covariance plot.
+        fig_svd : instance of matplotlib.pyplot.Figure | None
+            The SVD spectra plot of the covariance.
+        """
+        from .viz.misc import plot_cov
+        return plot_cov(self, info, exclude, colorbar, proj, show_svd, show)
+
 
 ###############################################################################
 # IO
diff --git a/mne/viz/misc.py b/mne/viz/misc.py
--- a/mne/viz/misc.py
+++ b/mne/viz/misc.py
@@ -48,8 +48,8 @@ def plot_cov(cov, info, exclude=[], colorbar=True, proj=False, show_svd=True,
     show : bool
         Call pyplot.show() as the end or not.
     show_svd : bool
-        Plot also singular values of the noise covariance for each sensor type.
-        We show square roots ie. standard deviations.
+        Plot also singular values of the noise covariance for each sensor
+        type. We show square roots ie. standard deviations.
     verbose : bool, str, int, or None
         If not None, override default verbose level (see mne.verbose).
 


Test patch:
diff --git a/mne/viz/tests/test_misc.py b/mne/viz/tests/test_misc.py
--- a/mne/viz/tests/test_misc.py
+++ b/mne/viz/tests/test_misc.py
@@ -17,7 +17,7 @@
                  SourceEstimate)
 from mne.datasets import testing
 from mne.minimum_norm import read_inverse_operator
-from mne.viz import (plot_cov, plot_bem, plot_events, plot_source_spectrogram,
+from mne.viz import (plot_bem, plot_events, plot_source_spectrogram,
                      plot_snr_estimate)
 from mne.utils import requires_nibabel, run_tests_if_main
 
@@ -52,7 +52,7 @@ def test_plot_cov():
     """
     raw = _get_raw()
     cov = read_cov(cov_fname)
-    fig1, fig2 = plot_cov(cov, raw.info, proj=True, exclude=raw.ch_names[6:])
+    fig1, fig2 = cov.plot(raw.info, proj=True, exclude=raw.ch_names[6:])
     plt.close('all')