matplotlib LassoSelector를 사용하여 산점도에서 일부 포인트를 선택하고 선택된 포인트에 대해서만 별도의 그림을 생성하려고합니다. 두 번째 플롯에서 다른 matplotlib 위젯을 사용하려고하면 작동하지 않지만 오류나 경고 메시지는 없습니다. 아래는 LassoSelector와 SpanSelector가 사용 된 최소 예제입니다.Matplotlib 위젯이 다른 matplotlib 위젯에 의해 생성 된 플롯에 사용되었습니다
다른 위젯을 사용해 보았습니다. 버튼 위젯은 버튼을 표시하지만 버튼 누름에 대한 작업은 수행되지 않습니다.
import numpy as np
from matplotlib.pyplot import *
from matplotlib.widgets import SpanSelector, LassoSelector
from matplotlib.path import Path
def onselect(verts):
global xys,data
#get indexes of selected points
path = Path(verts)
xysn = xys.get_offsets()
ind = np.nonzero([path.contains_point(xy) for xy in xysn])[0]
#plot the second figure
fig=figure(2)
ax=fig.add_subplot(111)
ax.hist(data[:,0][ind],10)
#this should be executed when SpanSelector is used
def action(min,max):
print min,max
#try to do SpanSelector (this fails)
span=SpanSelector(ax,action,'horizontal')
show()
#initialize a figure
fig=figure(1)
ax=fig.add_subplot(111)
#create data
data=np.array([[1,6], [4,8],[0,4],[4,2],[9,6],[10,8],[2,2],[5,5],[0,4],[4,5]])
#plot data
xys=ax.scatter(data[:,0],data[:,1])
#select point by drawing a path around them
lasso = LassoSelector(ax, onselect=onselect)
show()