Event hookups and subheadings in matplotlib

I have something that seems like a simple task, but I'm not sure how and where to start. I currently have a series of subheadings displayed on a single figure. Now I want to add / connect an event handler on each subtitle, so when the user clicks on one of the subnets, the selected section will be opened in a separate figure / window.
I want to know if this is possible, and if someone can formulate a little simple code to illustrate how this can be done. I should also mention that the only type of plot I use that interests me is colormaps (using imshow ()).

+1
source share
1 answer

You should read this tutorial.

Basically, you need to define a function that takes one argument eventand then attaches it to your figure 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)
+4
source

Source: https://habr.com/ru/post/1653800/


All Articles