From a7bfef2f339a9c00e6cb33046531215a1dcfe255 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Thu, 30 Jul 2015 16:15:58 -0400 Subject: [PATCH 1/8] mep12 on quiver_demo.py --- examples/pylab_examples/quiver_demo.py | 141 +++++++++++++++---------- 1 file changed, 83 insertions(+), 58 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 1cfcb67cb753..df4b2def76c6 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -8,76 +8,101 @@ The workaround is to manually expand the axes. ''' -from pylab import * +import matplotlib.pyplot as plt +import numpy as np from numpy import ma -X, Y = meshgrid(arange(0, 2*pi, .2), arange(0, 2*pi, .2)) -U = cos(X) -V = sin(Y) +X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2)) +U = np.cos(X) +V = np.sin(Y) -#1 -figure() -Q = quiver(U, V) -qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', - fontproperties={'weight': 'bold'}) -l, r, b, t = axis() +# 1 +plt.figure() +Q = plt.quiver(U, V) +qk = plt.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', + fontproperties={'weight': 'bold'}) +l, r, b, t = plt.axis() dx, dy = r - l, t - b -axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy]) +plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy]) -title('Minimal arguments, no kwargs') +plt.title('Minimal arguments, no kwargs') -#2 -figure() -Q = quiver(X, Y, U, V, units='width') -qk = quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', - labelpos='E', - coordinates='figure', - fontproperties={'weight': 'bold'}) -axis([-1, 7, -1, 7]) -title('scales with plot width, not view') +# 2 +plt.figure() +Q = plt.quiver(X, Y, U, V, units='width') +qk = plt.quiverkey(Q, 0.9, 0.95, 2, r'$2 \frac{m}{s}$', + labelpos='E', + coordinates='figure', + fontproperties={'weight': 'bold'}) +plt.axis([-1, 7, -1, 7]) +plt.title('scales with plot width, not view') -#3 -figure() -Q = quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], - pivot='mid', color='r', units='inches') -qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) -plot(X[::3, ::3], Y[::3, ::3], 'k.') -axis([-1, 7, -1, 7]) -title("pivot='mid'; every third arrow; units='inches'") +# 3 +plt.figure() +Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], + pivot='mid', color='r', units='inches') +qk = plt.quiverkey( + Q, + 0.5, + 0.03, + 1, + r'$1 \frac{m}{s}$', + fontproperties={ + 'weight': 'bold'}) +plt.plot(X[::3, ::3], Y[::3, ::3], 'k.') +plt.axis([-1, 7, -1, 7]) +plt.title("pivot='mid'; every third arrow; units='inches'") -#4 -figure() -M = sqrt(pow(U, 2) + pow(V, 2)) -Q = quiver(X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1/0.15) -qk = quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', - labelpos='E', - fontproperties={'weight': 'bold'}) -plot(X, Y, 'k.') -axis([-1, 7, -1, 7]) -title("scales with x view; pivot='tip'") +# 4 +plt.figure() +M = np.sqrt(np.power(U, 2) + np.power(V, 2)) +Q = plt.quiver( + X, + Y, + U, + V, + M, + units='x', + pivot='tip', + width=0.022, + scale=1 / + 0.15) +qk = plt.quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', + labelpos='E', + fontproperties={'weight': 'bold'}) +plt.plot(X, Y, 'k.') +plt.axis([-1, 7, -1, 7]) +plt.title("scales with x view; pivot='tip'") -#5 -figure() -Q = quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], - color='r', units='x', - linewidths=(2,), edgecolors=('k'), headaxislength=5) -qk = quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', fontproperties={'weight': 'bold'}) -axis([-1, 7, -1, 7]) -title("triangular head; scale with x view; black edges") +# 5 +plt.figure() +Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], + color='r', units='x', + linewidths=(2,), edgecolors=('k'), headaxislength=5) +qk = plt.quiverkey( + Q, + 0.5, + 0.03, + 1, + r'$1 \frac{m}{s}$', + fontproperties={ + 'weight': 'bold'}) +plt.axis([-1, 7, -1, 7]) +plt.title("triangular head; scale with x view; black edges") -#6 -figure() -M = zeros(U.shape, dtype='bool') -M[U.shape[0]/3:2*U.shape[0]/3, U.shape[1]/3:2*U.shape[1]/3] = True +# 6 +plt.figure() +M = np.zeros(U.shape, dtype='bool') +M[U.shape[0] / 3:2 * U.shape[0] / 3, U.shape[1] / 3:2 * U.shape[1] / 3] = True U = ma.masked_array(U, mask=M) V = ma.masked_array(V, mask=M) -Q = quiver(U, V) -qk = quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', - fontproperties={'weight': 'bold'}) -l, r, b, t = axis() +Q = plt.quiver(U, V) +qk = plt.quiverkey(Q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W', + fontproperties={'weight': 'bold'}) +l, r, b, t = plt.axis() dx, dy = r - l, t - b -axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy]) -title('Minimal arguments, no kwargs - masked values') +plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy]) +plt.title('Minimal arguments, no kwargs - masked values') -show() +plt.show() From 7b35de2b5c8a820a10d4601aed12f004a1a668ee Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Thu, 30 Jul 2015 16:33:00 -0400 Subject: [PATCH 2/8] pep8 changes --- examples/pylab_examples/quiver_demo.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index df4b2def76c6..7a96a2bcbc15 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -56,17 +56,11 @@ # 4 plt.figure() M = np.sqrt(np.power(U, 2) + np.power(V, 2)) -Q = plt.quiver( - X, - Y, - U, - V, - M, - units='x', - pivot='tip', - width=0.022, - scale=1 / - 0.15) +Q = plt.quiver(X, Y, U, V, M, + units='x', + pivot='tip', + width=0.022, + scale=1 / 0.15) qk = plt.quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', labelpos='E', fontproperties={'weight': 'bold'}) @@ -79,14 +73,8 @@ Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], color='r', units='x', linewidths=(2,), edgecolors=('k'), headaxislength=5) -qk = plt.quiverkey( - Q, - 0.5, - 0.03, - 1, - r'$1 \frac{m}{s}$', - fontproperties={ - 'weight': 'bold'}) +qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', + fontproperties={'weight': 'bold'}) plt.axis([-1, 7, -1, 7]) plt.title("triangular head; scale with x view; black edges") From fd83166709493e2952c956bf9b5b41e096a38c5e Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 09:36:59 -0400 Subject: [PATCH 3/8] changed convoluted square roots to hypot --- examples/pylab_examples/quiver_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 7a96a2bcbc15..f0410c82bb5f 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -55,7 +55,7 @@ # 4 plt.figure() -M = np.sqrt(np.power(U, 2) + np.power(V, 2)) +M = np.hypot(U, V) Q = plt.quiver(X, Y, U, V, M, units='x', pivot='tip', From 156fa27c670a6d742881b389280e165c98301d8d Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 09:57:47 -0400 Subject: [PATCH 4/8] tidied up the slicing on line 84 --- examples/pylab_examples/quiver_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index f0410c82bb5f..09b37d581915 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -81,7 +81,7 @@ # 6 plt.figure() M = np.zeros(U.shape, dtype='bool') -M[U.shape[0] / 3:2 * U.shape[0] / 3, U.shape[1] / 3:2 * U.shape[1] / 3] = True +M[U.shape[0]/3 : 2*U.shape[0]/3, U.shape[1]/3 : 2*U.shape[1]/3] = True U = ma.masked_array(U, mask=M) V = ma.masked_array(V, mask=M) Q = plt.quiver(U, V) From c1692f3b241b2bbd4a8fb6c69d141730d5ad87f8 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 20:43:09 -0400 Subject: [PATCH 5/8] split line 84 into two --- examples/pylab_examples/quiver_demo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 09b37d581915..1536be4b5ee1 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -81,7 +81,8 @@ # 6 plt.figure() M = np.zeros(U.shape, dtype='bool') -M[U.shape[0]/3 : 2*U.shape[0]/3, U.shape[1]/3 : 2*U.shape[1]/3] = True +M[U.shape[0]/3:2*U.shape[0]/3, + U.shape[1]/3:2*U.shape[1]/3] = True U = ma.masked_array(U, mask=M) V = ma.masked_array(V, mask=M) Q = plt.quiver(U, V) From 3de4e9fcce6896e48987597261f43e33f2ff71f3 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Fri, 31 Jul 2015 23:04:46 -0400 Subject: [PATCH 6/8] pep8 changes --- examples/pylab_examples/quiver_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 1536be4b5ee1..6b06ca7091a5 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -81,7 +81,7 @@ # 6 plt.figure() M = np.zeros(U.shape, dtype='bool') -M[U.shape[0]/3:2*U.shape[0]/3, +M[U.shape[0]/3:2*U.shape[0]/3, U.shape[1]/3:2*U.shape[1]/3] = True U = ma.masked_array(U, mask=M) V = ma.masked_array(V, mask=M) From ca65082ddae197d72b64d87cb24031afb73fc14c Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Mon, 3 Aug 2015 16:08:02 -0400 Subject: [PATCH 7/8] Fixed autopep8 issues. --- examples/pylab_examples/quiver_demo.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 6b06ca7091a5..0a18a7eb3993 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -23,7 +23,7 @@ fontproperties={'weight': 'bold'}) l, r, b, t = plt.axis() dx, dy = r - l, t - b -plt.axis([l - 0.05 * dx, r + 0.05 * dx, b - 0.05 * dy, t + 0.05 * dy]) +plt.axis([l - 0.05*dx, r + 0.05*dx, b - 0.05*dy, t + 0.05*dy]) plt.title('Minimal arguments, no kwargs') @@ -41,14 +41,8 @@ plt.figure() Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', color='r', units='inches') -qk = plt.quiverkey( - Q, - 0.5, - 0.03, - 1, - r'$1 \frac{m}{s}$', - fontproperties={ - 'weight': 'bold'}) +qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', + fontproperties={'weight': 'bold'}) plt.plot(X[::3, ::3], Y[::3, ::3], 'k.') plt.axis([-1, 7, -1, 7]) plt.title("pivot='mid'; every third arrow; units='inches'") From 4e20961607061405327761ed02824937a08b8550 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Tue, 4 Aug 2015 08:16:01 -0400 Subject: [PATCH 8/8] pep8 fixes --- examples/pylab_examples/quiver_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/quiver_demo.py b/examples/pylab_examples/quiver_demo.py index 0a18a7eb3993..d1f319ffa8f3 100644 --- a/examples/pylab_examples/quiver_demo.py +++ b/examples/pylab_examples/quiver_demo.py @@ -42,7 +42,7 @@ Q = plt.quiver(X[::3, ::3], Y[::3, ::3], U[::3, ::3], V[::3, ::3], pivot='mid', color='r', units='inches') qk = plt.quiverkey(Q, 0.5, 0.03, 1, r'$1 \frac{m}{s}$', - fontproperties={'weight': 'bold'}) + fontproperties={'weight': 'bold'}) plt.plot(X[::3, ::3], Y[::3, ::3], 'k.') plt.axis([-1, 7, -1, 7]) plt.title("pivot='mid'; every third arrow; units='inches'")