From 9f5c27f85c1fc45eaa3e7575d9f7285d2c8b5165 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 28 Jan 2017 13:11:42 +0000 Subject: [PATCH 1/5] Fix cohere-demo --- examples/pylab_examples/cohere_demo.py | 33 ++++++++++++-------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/examples/pylab_examples/cohere_demo.py b/examples/pylab_examples/cohere_demo.py index 96149c5d789b..78a4c12802b9 100644 --- a/examples/pylab_examples/cohere_demo.py +++ b/examples/pylab_examples/cohere_demo.py @@ -7,31 +7,28 @@ # Fixing random state for reproducibility np.random.seed(19680801) - -# make a little extra space between the subplots -plt.subplots_adjust(wspace=0.5) - dt = 0.01 t = np.arange(0, 30, dt) nse1 = np.random.randn(len(t)) # white noise 1 nse2 = np.random.randn(len(t)) # white noise 2 -r = np.exp(-t/0.05) +r = np.exp(-t / 0.05) -cnse1 = np.convolve(nse1, r, mode='same')*dt # colored noise 1 -cnse2 = np.convolve(nse2, r, mode='same')*dt # colored noise 2 +cnse1 = np.convolve(nse1, r, mode='same') * dt # colored noise 1 +cnse2 = np.convolve(nse2, r, mode='same') * dt # colored noise 2 # two signals with a coherent part and a random part -s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1 -s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2 +s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1 +s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2 + +fig, axs = plt.subplots(2, 1) +axs[0].plot(t, s1, t, s2) +axs[0].set_xlim(0, 5) +axs[0].set_xlabel('time') +axs[0].set_ylabel('s1 and s2') +axs[0].grid(True) -plt.subplot(211) -plt.plot(t, s1, t, s2) -plt.xlim(0, 5) -plt.xlabel('time') -plt.ylabel('s1 and s2') -plt.grid(True) +cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt) +axs[1].set_ylabel('coherence') -plt.subplot(212) -cxy, f = plt.cohere(s1, s2, 256, 1./dt) -plt.ylabel('coherence') +fig.tight_layout() plt.show() From a54d257286a33c6047fded3d1237011feddafa06 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 29 Jan 2017 11:03:34 +0000 Subject: [PATCH 2/5] Add exaple title to cohere_demo --- examples/pylab_examples/cohere_demo.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/pylab_examples/cohere_demo.py b/examples/pylab_examples/cohere_demo.py index 78a4c12802b9..1aec8b308d97 100644 --- a/examples/pylab_examples/cohere_demo.py +++ b/examples/pylab_examples/cohere_demo.py @@ -1,5 +1,9 @@ """ -Compute the coherence of two signals +===================================== +Plotting the coherence of two signals +===================================== + +An example showing how to plot the coherence of two signals. """ import numpy as np import matplotlib.pyplot as plt From 7f81351cea5b04d3019c80ffc0c257be76c9603d Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 29 Jan 2017 11:23:06 +0000 Subject: [PATCH 3/5] Move cohere_demo to lines_bars_and_markers --- .../{pylab_examples => lines_bars_and_markers}/cohere_demo.py | 0 examples/tests/backend_driver.py | 2 +- lib/matplotlib/axes/_axes.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename examples/{pylab_examples => lines_bars_and_markers}/cohere_demo.py (100%) diff --git a/examples/pylab_examples/cohere_demo.py b/examples/lines_bars_and_markers/cohere_demo.py similarity index 100% rename from examples/pylab_examples/cohere_demo.py rename to examples/lines_bars_and_markers/cohere_demo.py diff --git a/examples/tests/backend_driver.py b/examples/tests/backend_driver.py index cf5a79b10036..6a62be831727 100755 --- a/examples/tests/backend_driver.py +++ b/examples/tests/backend_driver.py @@ -52,6 +52,7 @@ files['lines'] = [ 'barh_demo.py', + 'cohere_demo', 'fill_demo.py', 'fill_demo_features.py', 'line_demo_dash_control.py', @@ -127,7 +128,6 @@ 'barcode_demo.py', 'boxplot_demo.py', 'broken_barh.py', - 'cohere_demo.py', 'color_by_yvalue.py', 'color_demo.py', 'colorbar_tick_labelling_demo.py', diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 56c99d9b3ec1..fe284b7b030c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7082,7 +7082,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, Examples -------- - .. plot:: mpl_examples/pylab_examples/cohere_demo.py + .. plot:: mpl_examples/lines_bars_and_markers/cohere_demo.py """ if not self._hold: self.cla() From 998af8b6b2e4d660e055960298716344e9adac5e Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 29 Jan 2017 11:25:58 +0000 Subject: [PATCH 4/5] Add in missing .py --- examples/tests/backend_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tests/backend_driver.py b/examples/tests/backend_driver.py index 6a62be831727..370c794fe47e 100755 --- a/examples/tests/backend_driver.py +++ b/examples/tests/backend_driver.py @@ -52,7 +52,7 @@ files['lines'] = [ 'barh_demo.py', - 'cohere_demo', + 'cohere_demo.py', 'fill_demo.py', 'fill_demo_features.py', 'line_demo_dash_control.py', From f406d7dd494048a339fe5c48f26d2cbe6e629d40 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 7 Feb 2017 23:00:05 +0000 Subject: [PATCH 5/5] Remove convolution from cohere_demo --- examples/lines_bars_and_markers/cohere_demo.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/examples/lines_bars_and_markers/cohere_demo.py b/examples/lines_bars_and_markers/cohere_demo.py index 1aec8b308d97..370149695398 100644 --- a/examples/lines_bars_and_markers/cohere_demo.py +++ b/examples/lines_bars_and_markers/cohere_demo.py @@ -15,18 +15,14 @@ t = np.arange(0, 30, dt) nse1 = np.random.randn(len(t)) # white noise 1 nse2 = np.random.randn(len(t)) # white noise 2 -r = np.exp(-t / 0.05) -cnse1 = np.convolve(nse1, r, mode='same') * dt # colored noise 1 -cnse2 = np.convolve(nse2, r, mode='same') * dt # colored noise 2 - -# two signals with a coherent part and a random part -s1 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse1 -s2 = 0.01 * np.sin(2 * np.pi * 10 * t) + cnse2 +# Two signals with a coherent part at 10Hz and a random part +s1 = np.sin(2 * np.pi * 10 * t) + nse1 +s2 = np.sin(2 * np.pi * 10 * t) + nse2 fig, axs = plt.subplots(2, 1) axs[0].plot(t, s1, t, s2) -axs[0].set_xlim(0, 5) +axs[0].set_xlim(0, 2) axs[0].set_xlabel('time') axs[0].set_ylabel('s1 and s2') axs[0].grid(True)