def toggle_images(event):
 if (event.key != 't'):
  return
 b1 = im1.get_visible()
 b2 = im2.get_visible()
 im1.set_visible((not b1))
 im2.set_visible((not b2))
 plt.draw()

def toggle_images ( event ) : if ( event . key != 't' ) : return b1 = im1 . get_visible ( ) b2 = im2 . get_visible ( ) im1 . set_visible ( ( not b1 ) ) im2 . set_visible ( ( not b2 ) ) plt . draw ( )
toggle the visible state of the two images .