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

Skip to content

MEP12 on toggle_images.py #4640

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions examples/pylab_examples/toggle_images.py
Original file line number Diff line number Diff line change
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()