久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 理论片中文字幕 | 久久精品视频一区二区 | 久草免费福利视频 | 男男成人高潮片免费网站 | 手机av在线免费观看 | 九九久久精品 | 国产精品日韩在线 | 欧美日韩一区二区三区视频 | 激情久久av | 欧美精品久久久久久久多人混战 | 香蕉视频色 | 天天舔天天操 | 高跟肉丝丝袜呻吟啪啪网站av | 国产精品一级 | 天天综合视频 | 国产成人99久久亚洲综合精品 | 久久精品导航 | www欧美 | 亚洲福利影院 | 天堂资源av | 97在线超碰 | 国产男女视频 | 爱情岛论坛av | 亚洲网站在线 | 免费一级全黄少妇性色生活片 | 国内精品一区二区 | 依人久久 | 成人免费黄色大片 | 国产aⅴ爽av久久久久成人 | 免费特级毛片 | 亚洲一区二区中文字幕 | 成人午夜又粗又硬又大 | 亚洲精品一区二区三区在线观看 | 成人激情视频在线观看 | 国产精品日韩精品 | 九九热在线观看 | 97福利视频| 九九热视频在线观看 | 亚洲看片 | 中文字幕在线观看网址 | 精品一区二区三区免费看 |