내가하기 matplotlib 그림과 상호 작용하기 위해 노력하고있어하지만 계획대로 일이 가지 않는 링크 기능을 사용하여 그림에 텍스트를 표시 할 수 없습니다 아래 파이썬하기 matplotlib는 ... 이벤트
은 샘플입니다 여기에 test_figure 클래스의 init 부분에서 그림 (그림 1)을 만들고, 하위 그림을 추가하고, 무작위 지점을 100 개 플롯하고, 텍스트 상자의 속성을 정의하고, 이벤트 ' pick_event '함수를 onpick() 함수에 전달합니다. 이 함수를 사용하면 데이터의 x 및 y 좌표를 사용하여이를 사용하여 선을 그려야하고 (그림 2) 동시에 텍스트를 사용하여 그림 1의 x 및 y 좌표를 표시해야합니다.마지막 부분을 제외하고 거의 모든 기능이 작동합니다 : 그림 1에는 x 및 y 좌표가 표시되지 않고 이유를 파악할 수 없습니다 ... 아이디어가 있습니까?
감사합니다. 당신이 콜백의
import numpy as np
import matplotlib.pyplot as plt
class test_figure:
def __init__(self):
self.fig = plt.figure(1)
self.ax = self.fig.add_subplot(111)
self.ax.set_title('Click on data')
# 3 pixels around point
line, = self.ax.plot(np.random.rand(100), 'o', picker=3)
self.fig.canvas.mpl_connect('pick_event', self.onpick)
def onpick(self, event):
thisline = event.artist
xdata = thisline.get_xdata()
ydata = thisline.get_ydata()
ind = event.ind
self.fig2 = plt.figure(2)
self.ax2 = self.fig2.add_subplot(111)
line, = self.ax2.plot(xdata[ind]*range(60)+ydata[ind])
self.fig.text(0.5,0.5,'pouet :'+str(xdata[ind]))
a = test_figure()
들여 쓰기를 수정할 수 있습니까? – tacaswell
완료, 죄송합니다! – bserra