Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ec9cee

Browse files
committed
Merge pull request #4630 from ericmjl/import-changes-zorder_demo
MEP12 pylab changes on zorder_demo.py
2 parents 0892d36 + 3d6bfcb commit 3ec9cee

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

examples/pylab_examples/zorder_demo.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,33 @@
2020
The second figure shows how to control the zorder of individual lines.
2121
"""
2222

23-
from pylab import *
24-
x = rand(20)
25-
y = rand(20)
23+
import matplotlib.pyplot as plt
24+
import numpy as np
2625

27-
subplot(211)
28-
plot(x, y, 'r', lw=3)
29-
scatter(x, y, s=120)
26+
x = np.random.random(20)
27+
y = np.random.random(20)
3028

31-
subplot(212)
32-
plot(x, y, 'r', zorder=1, lw=3)
33-
scatter(x, y, s=120, zorder=2)
29+
# Lines on top of scatter
30+
plt.figure()
31+
plt.subplot(211)
32+
plt.plot(x, y, 'r', lw=3)
33+
plt.scatter(x, y, s=120)
34+
plt.title('Lines on top of dots')
35+
36+
# Scatter plot on top of lines
37+
plt.subplot(212)
38+
plt.plot(x, y, 'r', zorder=1, lw=3)
39+
plt.scatter(x, y, s=120, zorder=2)
40+
plt.title('Dots on top of lines')
3441

3542
# A new figure, with individually ordered items
36-
x = frange(0, 2*pi, npts=100)
37-
figure()
38-
plot(x, sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top
39-
plot(x, cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom
40-
plot(x, sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3)
41-
axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2)
42-
l = legend()
43+
x = np.linspace(0, 2*np.pi, 100)
44+
plt.figure()
45+
plt.plot(x, np.sin(x), linewidth=10, color='black', label='zorder=10', zorder=10) # on top
46+
plt.plot(x, np.cos(1.3*x), linewidth=10, color='red', label='zorder=1', zorder=1) # bottom
47+
plt.plot(x, np.sin(2.1*x), linewidth=10, color='green', label='zorder=3', zorder=3)
48+
plt.axhline(0, linewidth=10, color='blue', label='zorder=2', zorder=2)
49+
plt.title('Custom order of elements')
50+
l = plt.legend()
4351
l.set_zorder(20) # put the legend on top
44-
45-
show()
52+
plt.show()

0 commit comments

Comments
 (0)