Event Connections and subplots in matplotlib

感情迁移 提交于 2019-12-10 20:32:23

问题


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()).


回答1:


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)


来源:https://stackoverflow.com/questions/14236290/event-connections-and-subplots-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!