From 1ee298612658786632aad395cbfc9629633d0098 Mon Sep 17 00:00:00 2001 From: domspad Date: Sat, 11 Jul 2015 15:12:48 -0500 Subject: [PATCH 1/2] pylab to plt and np --- examples/pylab_examples/anscombe.py | 63 +++++++++++++++-------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/examples/pylab_examples/anscombe.py b/examples/pylab_examples/anscombe.py index b5dd3b316d72..9e6b25e9eb0c 100755 --- a/examples/pylab_examples/anscombe.py +++ b/examples/pylab_examples/anscombe.py @@ -9,51 +9,52 @@ matplotlib fun for a rainy day """ -from pylab import * +import matplotlib.pyplot as plt +import numpy as np -x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) -y1 = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) -y2 = array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]) -y3 = array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]) -x4 = array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]) -y4 = array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]) +x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) +y1 = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) +y2 = np.array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]) +y3 = np.array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]) +x4 = np.array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]) +y4 = np.array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]) def fit(x): return 3 + 0.5*x -xfit = array([amin(x), amax(x)]) +xfit = np.array([np.amin(x), np.amax(x)]) -subplot(221) -plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2) -axis([2, 20, 2, 14]) -setp(gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) -text(3, 12, 'I', fontsize=20) +plt.subplot(221) +plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2) +plt.axis([2, 20, 2, 14]) +plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) +plt.text(3, 12, 'I', fontsize=20) -subplot(222) -plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) -axis([2, 20, 2, 14]) -setp(gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) -text(3, 12, 'II', fontsize=20) +plt.subplot(222) +plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) +plt.axis([2, 20, 2, 14]) +plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) +plt.text(3, 12, 'II', fontsize=20) -subplot(223) -plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2) -axis([2, 20, 2, 14]) -text(3, 12, 'III', fontsize=20) -setp(gca(), yticks=(4, 8, 12), xticks=(0, 10, 20)) +plt.subplot(223) +plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2) +plt.axis([2, 20, 2, 14]) +plt.text(3, 12, 'III', fontsize=20) +plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20)) -subplot(224) +plt.subplot(224) -xfit = array([amin(x4), amax(x4)]) -plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2) -axis([2, 20, 2, 14]) -setp(gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) -text(3, 12, 'IV', fontsize=20) +xfit = np.array([np.amin(x4), np.amax(x4)]) +plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2) +plt.axis([2, 20, 2, 14]) +plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) +plt.text(3, 12, 'IV', fontsize=20) # verify the stats pairs = (x, y1), (x, y2), (x, y3), (x4, y4) for x, y in pairs: - print('mean=%1.2f, std=%1.2f, r=%1.2f' % (mean(y), std(y), corrcoef(x, y)[0][1])) + print('mean=%1.2f, std=%1.2f, r=%1.2f' % (np.mean(y), np.std(y), np.corrcoef(x, y)[0][1])) -show() +plt.show() From 37206713b17d8dc1e541c8c0008d3c583f07d6df Mon Sep 17 00:00:00 2001 From: domspad Date: Thu, 16 Jul 2015 23:27:17 -0700 Subject: [PATCH 2/2] pep8 --- examples/pylab_examples/anscombe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pylab_examples/anscombe.py b/examples/pylab_examples/anscombe.py index 9e6b25e9eb0c..3392bc55fd5e 100755 --- a/examples/pylab_examples/anscombe.py +++ b/examples/pylab_examples/anscombe.py @@ -9,7 +9,7 @@ matplotlib fun for a rainy day """ -import matplotlib.pyplot as plt +import matplotlib.pyplot as plt import numpy as np x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5])