4

I have what seems to be a simple task yet I am not sure how and where to start. What I currently have is a series of subplots displayed on one figure. Now I want to add/connect an event handler on each subplot, such that when the user clicks on one of the subplots the plot that was selected would be opened in a separate figure/window.
I want to know if this is possible and if someone could formulate a small simple code to illustrate how this can be done. I should also mention that the only type of plot that I am using and interested in are colormaps (using imshow()).

Zephyr
  • 11,891
  • 53
  • 45
  • 80
user1750948
  • 719
  • 2
  • 10
  • 27

1 Answers1

8

You should read this tutorial.

Basically you need to define function which takes one arguement event and then attach it to your figure's canvas:

def open_new_figure(event):
    if event.inaxes is not None:
        ax = event.inaxes
        # you now have the axes object for that the user clicked on
        # you can use ax.children() to figure out which img artist is in this
        # axes and extract the data from it

cid = fig.canvas.mpl_connect('button_press_event', open_new_figure)
tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • 1
    Thank you very much! Comments in your code helped me to understand how to find needed axes. – Kanat Apr 27 '16 at 14:04