久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 matplotlib 存儲鼠標單擊事件坐標

Store mouse click event coordinates with matplotlib(使用 matplotlib 存儲鼠標單擊事件坐標)
本文介紹了使用 matplotlib 存儲鼠標單擊事件坐標的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試在 matplotlib 中實現一個簡單的鼠標單擊事件.我希望繪制一個圖形,然后使用鼠標選擇積分的下限和上限.到目前為止,我能夠將坐標打印到屏幕上,但不能存儲它們以供以后在程序中使用.我也想在第二次鼠標點擊后退出與圖的連接.

I am trying to implement a simple mouse click event in matplotlib. I wish to plot a figure then use the mouse to select the lower and upper limits for integration. So far I am able to print the coordinates to screen but not store them for later use in the program. I would also like to exit the connection to the figure after the second mouse click.

下面是當前繪制然后打印坐標的代碼.

Below is the code which currently plots and then prints the coordinates.

我的問題:

如何將圖形中的坐標存儲到列表中?即點擊 = [xpos, ypos]

How can I store coordinates from the figure to list? i.e. click = [xpos, ypos]

是否有可能獲得兩組 x 坐標以便對該段線進行簡單的積分?

Is it possible to get two sets of x coordinates in order to do a simple integration over that section of line?

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10,10)
y = x**2

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)

def onclick(event):
    global ix, iy
    ix, iy = event.xdata, event.ydata
    print 'x = %d, y = %d'%(
        ix, iy)

    global coords
    coords = [ix, iy]

    return coords


for i in xrange(0,1):

    cid = fig.canvas.mpl_connect('button_press_event', onclick)


plt.show()

推薦答案

mpl_connect 只需調用一次即可將事件連接到事件處理程序.它將開始監聽點擊事件,直到您斷開連接.你可以使用

mpl_connect needs to be called just once to connect the event to event handler. It will start listening to click event until you disconnect. And you can use

fig.canvas.mpl_disconnect(cid)

斷開事件掛鉤.

你想做的是這樣的:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(-10,10)
y = x**2

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x,y)

coords = []

def onclick(event):
    global ix, iy
    ix, iy = event.xdata, event.ydata
    print 'x = %d, y = %d'%(
        ix, iy)

    global coords
    coords.append((ix, iy))

    if len(coords) == 2:
        fig.canvas.mpl_disconnect(cid)

    return coords
cid = fig.canvas.mpl_connect('button_press_event', onclick)

這篇關于使用 matplotlib 存儲鼠標單擊事件坐標的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 欧美日韩1区2区3区 欧美久久一区 | 91porn在线| 99精品国产一区二区三区 | 欧美日韩中文字幕在线 | 一级黄色片网站 | 欧美日韩理论 | 天天干狠狠干 | 亚洲欧洲视频 | 国产一区二区在线免费播放 | 欧美日韩亚洲国产 | 久久久男人的天堂 | 国产精品久久在线观看 | 久久久久久国产 | 久久日韩粉嫩一区二区三区 | 亚洲成人免费在线观看 | 一区二区三区精品视频 | 欧美在线高清 | 中文字幕一页二页 | 亚洲综合在线一区 | 一区二区三区免费看 | 男人天堂999 | 中文字幕一区二区三区在线视频 | 嫩草国产 | 亚洲视频www| 久久这里有精品 | 亚洲精品视频在线 | 国产精品亚洲片在线播放 | 午夜色婷婷 | 一本一道久久a久久精品蜜桃 | 久久久久免费观看 | 亚洲一区国产 | 日韩中文字幕 | 天天操人人干 | 日本一区二区不卡 | 亚洲精品久久久一区二区三区 | 日中文字幕在线 | 日韩播放 | 欧美视频一区二区三区 | 精品久久久久久久久久久 | 精品国产18久久久久久二百 | 中文字幕亚洲视频 |