由于我没有得到任何答案,也找不到关于该主题的太多内容,因此我是这样解决这个问题的:我添加了一个预程序,允许用户放大所选区域。当该区域适合点拾取时,用户只需按“Enter”并继续ginput
。
from __future__ import print_function
from pylab import arange, plot, sin, ginput, show
import matplotlib as plt
from pylab import *
import numpy as np
def closest_point(vec,val):
ind = np.where(vec==min(vec,key=lambda x:abs(x-val)))
return ind[0][0]
t = np.linspace(0,250,5000)
y = sin(t)
fig = plt.figure()
plt.suptitle('chosing points over a possibly dense signal...',fontsize=14)
zoom_ok = False
while not zoom_ok:
plt.plot(t,y)
plt.title('1 - click on the two corners of the area to enlarge',fontsize=12)
zoom = ginput(2,timeout=-1)
xzoom = np.zeros([0])
for i in range(2):
xzoom = np.concatenate((xzoom,[int(closest_point(t,zoom[i][0]))]))
temps_zoom = t[xzoom[0]:xzoom[1]]
dep_zoom = y[xzoom[0]:xzoom[1]]
plt.clf()
plt.plot(temps_zoom,dep_zoom,'b')
plt.title('2 - if zoom ok -> press Enter, otherwise -> mouse click',fontsize=12)
zoom_ok = plt.waitforbuttonpress()
plt.title('3 - you may now select the points ',fontsize=16)
x = ginput(2,timeout=-1)
plt.show()