久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 亚洲精品久久久久久久久久久 | 国产亚洲一区精品 | 亚洲欧洲在线看 | 一区二区三区欧美在线 | 人人操日日干 | 91影院| 黄色一级大片在线免费看产 | 欧美性影院 | 国产精品揄拍一区二区 | 女人一区 | 91麻豆精品国产91久久久更新资源速度超快 | 黄色在线免费网站 | 亚洲欧洲精品成人久久奇米网 | 最新中文字幕在线 | 日韩电影一区 | 91麻豆精品一区二区三区 | 午夜爱爱网 | 欧美色999| 亚洲精选一区 | 久久国产视频播放 | 国产黄色小视频 | 欧美日韩久久 | 国产成人精品久久二区二区91 | 欧美 日韩 综合 | 日韩毛片| 国产黄色av网站 | 中文字幕视频在线观看 | 欧美激情a∨在线视频播放 成人免费共享视频 | 国产精品久久久久无码av | 免费看黄色视屏 | 精久久久 | 欧美日韩专区 | 日韩av免费在线观看 | 久久综合狠狠综合久久综合88 | 国产成人精品在线播放 | 亚洲精品中文字幕中文字幕 | 91视频一88av | 日韩在线小视频 | 成年免费大片黄在线观看一级 | www.毛片 | 欧美久久久网站 |