From 70f05e1718d30a6fe38e8296bede11e037ff0a78 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 11 Jul 2015 11:48:06 -0500 Subject: [PATCH 1/2] MEP12 pylab changes on zorder_demo.py Changes: 1. Changed pylab namespace to matplotlib and numpy. 2. Added titles to figure plots to highlight z-order edits. --- examples/pylab_examples/zorder_demo.py | 43 +++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/examples/pylab_examples/zorder_demo.py b/examples/pylab_examples/zorder_demo.py index 0ffb76ccdf6a..f9915e76976a 100755 --- a/examples/pylab_examples/zorder_demo.py +++ b/examples/pylab_examples/zorder_demo.py @@ -20,26 +20,33 @@ The second figure shows how to control the zorder of individual lines. """ -from pylab import * -x = rand(20) -y = rand(20) +import matplotlib.pyplot as plt +import numpy as np -subplot(211) -plot(x, y, 'r', lw=3) -scatter(x, y, s=120) +x = np.random.random(20) +y = np.random.random(20) -subplot(212) -plot(x, y, 'r', zorder=1, lw=3) -scatter(x, y, s=120, zorder=2) +# Lines on top of scatter +plt.figure() +plt.subplot(211) +plt.plot(x, y, 'r', lw=3) +plt.scatter(x, y, s=120) +plt.title('Lines on top of dots') + +# Scatter plot on top of lines +plt.subplot(212) +plt.plot(x, y, 'r', zorder=1, lw=3) +plt.scatter(x, y, s=120, zorder=2) +plt.title('Dots on top of lines') # A new figure, with individually ordered items -x = frange(0, 2*pi, npts=100) -figure() -plot(x, sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top -plot(x, cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom -plot(x, sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3) -axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2) -l = legend() +x = np.linspace(0, 2*np.pi, 100) +plt.figure() +plt.plot(x, np.sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top +plt.plot(x, np.cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom +plt.plot(x, np.sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3) +plt.axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2) +plt.title('Custom order of elements') +l = plt.legend() l.set_zorder(20) # put the legend on top - -show() +plt.show() \ No newline at end of file From 3d6bfcbdc40f0bdcaae31a2fece067f0d8a20e6f Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sat, 11 Jul 2015 14:02:28 -0500 Subject: [PATCH 2/2] PEP8 changes --- examples/pylab_examples/zorder_demo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pylab_examples/zorder_demo.py b/examples/pylab_examples/zorder_demo.py index f9915e76976a..400cc060c784 100755 --- a/examples/pylab_examples/zorder_demo.py +++ b/examples/pylab_examples/zorder_demo.py @@ -20,7 +20,7 @@ The second figure shows how to control the zorder of individual lines. """ -import matplotlib.pyplot as plt +import matplotlib.pyplot as plt import numpy as np x = np.random.random(20) @@ -49,4 +49,4 @@ plt.title('Custom order of elements') l = plt.legend() l.set_zorder(20) # put the legend on top -plt.show() \ No newline at end of file +plt.show()