2013-01-09 32 views
1

我有什麼似乎是一個簡單的任務,但我不知道如何以及從哪裏開始。我現在所擁有的是在一個圖上顯示的一系列子圖。現在我想在每個子圖上添加/連接一個事件處理程序,這樣當用戶點擊其中一個子圖時,所選的圖將在單獨的圖形/窗口中打開。
我想知道這是否可能,如果有人可以制定一個簡單的代碼來說明如何做到這一點。 我還應該提到,我正在使用和感興趣的唯一一種情節是colormap(使用imshow())。事件連接和matplotlib中的子圖

回答

4

您應該閱讀this教程。

基本上你需要定義函數,它接受一個arguement event,然後將其連接到你的人物的帆布:

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) 
+0

非常感謝您!你的代碼中的評論幫助我理解如何找到需要的軸。 – Kanat