How to get a (x,y) position pointing with mouse in a interactive plot (Python)?(如何在交互式绘图(Python)中用鼠标指向(x,y)位置?)
问题描述
我使用 ipython 笔记本(带有神奇的 %matplotlib nbagg
).我正在查看 matplotlib.widget.Cursor
但仅查看光标 widgets.Cursor.所以我想在图中选择两个点并获取初始和最终的 x,y 位置(例如时间与温度,选择点必须返回初始和最终时间).我需要它来手动选择任意间隔.我认为它类似于 获取全局 x,y 位置,但我在那篇文章中不太了解.
I use ipython notebook (with the magic %matplotlib nbagg
). I was reviewing the matplotlib.widget.Cursor
but the cursor is only viewed widgets.Cursor. So I'd like to select two points clicking in the plot and get the initial and final x,y-position (e.g. time vs Temperature, selecting to points must return initial and final time). I need it for selecting manually an arbitrary interval. I think it's similar to get global x,y position, but I didn't understand well in that post.
如何在交互式绘图 (Python) 中获得鼠标指向的 (x,y) 位置?
How can I get a (x,y) position pointing with mouse in a interactive plot (Python)?
观察.类似于 IDL 中的 CURSOR 过程
Obs. Something similar to CURSOR Procedure in IDL
推荐答案
事件处理应该工作.
import matplotlib.pylab as plt
import numpy as np
f,a = plt.subplots()
x = np.linspace(1,10,100)
y = np.sin(x)
a.plot(x,y)
pos = []
def onclick(event):
pos.append([event.xdata,event.ydata])
f.canvas.mpl_connect('button_press_event', onclick)
f.show()
每次单击时,当前光标位置都会附加到 pos.
On each click the current cursor position is appended to pos.
这篇关于如何在交互式绘图(Python)中用鼠标指向(x,y)位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在交互式绘图(Python)中用鼠标指向(x,y)位置?


- YouTube API v3 返回截断的观看记录 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01