Pyplot: Refreshing an imshow() Window
<p>I've got two methods: generate_window() which shows an image and on_click() which reacts to a click on the window showing the image. They look like this:</p>

<pre><code>def generate_panel(img):
  plt.figure()
  ax = plt.gca()
  fig = plt.gcf()
  implot = ax.imshow(img)
  # When a colour is clicked on the image an event occurs
  cid = fig.canvas.mpl_connect('button_press_event', onclick)
  plt.show()

def onclick(event):
  if event.xdata != None and event.ydata != None:
    # Change the contents of the plt window here
</code></pre>

<p>On the last line of the code I want to be able to change the image shown in the plt window but I can't seem to get it to work. I've tried set_data() and draw() in different places but that hasn't worked. Any suggestions? Thanks in advance.</p>