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

Skip to content

Commit e71e64e

Browse files
committed
Merge pull request #4640 from ericmjl/mep12-toggle_images.py
MEP12 on toggle_images.py
2 parents 12fa90e + e9cdd79 commit e71e64e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/pylab_examples/toggle_images.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
1818
"""
1919

20-
from pylab import *
20+
import matplotlib.pyplot as plt
21+
import numpy as np
2122

2223
# two images x1 is initially visible, x2 is not
23-
x1 = rand(100, 100)
24-
x2 = rand(150, 175)
24+
x1 = np.random.random((100, 100))
25+
x2 = np.random.random((150, 175))
2526

2627
# arbitrary extent - both images must have same extent if you want
2728
# them to be resampled into the same axes space
2829
extent = (0, 1, 0, 1)
29-
im1 = imshow(x1, extent=extent)
30-
im2 = imshow(x2, extent=extent, hold=True)
30+
im1 = plt.imshow(x1, extent=extent)
31+
im2 = plt.imshow(x2, extent=extent, hold=True)
3132
im2.set_visible(False)
3233

3334

@@ -39,8 +40,8 @@ def toggle_images(event):
3940
b2 = im2.get_visible()
4041
im1.set_visible(not b1)
4142
im2.set_visible(not b2)
42-
draw()
43+
plt.draw()
4344

44-
connect('key_press_event', toggle_images)
45+
plt.connect('key_press_event', toggle_images)
4546

46-
show()
47+
plt.show()

0 commit comments

Comments
 (0)