Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEP12 on toggle_images.py #4640

Merged
merged 3 commits into from Jul 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/pylab_examples/toggle_images.py
Expand Up @@ -17,17 +17,18 @@

"""

from pylab import *
import matplotlib.pyplot as plt
import numpy as np

# two images x1 is initially visible, x2 is not
x1 = rand(100, 100)
x2 = rand(150, 175)
x1 = np.random.random((100, 100))
x2 = np.random.random((150, 175))

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


Expand All @@ -39,8 +40,8 @@ def toggle_images(event):
b2 = im2.get_visible()
im1.set_visible(not b1)
im2.set_visible(not b2)
draw()
plt.draw()

connect('key_press_event', toggle_images)
plt.connect('key_press_event', toggle_images)

show()
plt.show()