diff --git a/examples/pylab_examples/zorder_demo.py b/examples/pylab_examples/zorder_demo.py index 0ffb76ccdf6a..400cc060c784 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()