사용자로부터 입력을 받아 .csv
형식으로 입력하고 matplotlib
을 사용하여 해당 값에 대한 그래프를 그려주는 응용 프로그램을 개발 중입니다. Tkinter에서 마우스로 선택 영역 그리기
def plotgraph():
x = []
y = []
data = text.get("1.0", END)
sepFile = data.split('\n')
for plotPair in sepFile:
xAndY = plotPair.split(',')
if len(xAndY[0]) != 0 and len(xAndY[1]) != 0:
x.append(float(xAndY[0]))
y.append(float(xAndY[1]))
graph = Figure(figsize=(5,4), dpi=100)
a = graph.add_subplot(111)
a.plot(x,y)
a.set_xlabel('Velocity')
a.set_ylabel('Absorbance')
canvas = FigureCanvasTkAgg(graph, master=RightFrame)
canvas.show()
canvas.get_tk_widget().grid(column=2, row=1, rowspan=2, sticky=(N, S, E, W))
나는 나에게 선택 후
x0, x1, y0, y1
을 제공
Tkinter
이
Matplotlib: draw a selection area in the shape of a rectangle with the mouse 같은 유사한 기능을합니다. 나는 이미 묻는 질문 작업 & 내 필요하지만 모르고 내가 내가 빈 TK에 창을 얻을이 코드를 실행하면 내가
__init__(self)
root = Tk()
class Annotate(object):
def __init__(self):
self.fig = mplfig.Figure(figsize=(1.5, 1.5))
self.ax = self.fig.add_subplot(111)
self.ax.plot([0,1,2,3,4],[0,8,9,5,3])
self.canvas = tkagg.FigureCanvasTkAgg(self.fig, master=root)
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
에 실수를하고있는 중이 야에 따라 사용자 지정할 수 있도록 만들 수 있습니다. 사람이 내가이
class Annotate(object):
def __init__(self):
print "Annotate is runing"
# rest of your code
root = Tk()
my_object = Annotate()
root.mainloop()
같은 목록 뭔가를 당신이 필요로하는 클래스를 사용하려면 실수
console/terminal/cmd.exe에서 실행 했습니까? 어쩌면 몇 가지 오류 메시지가있었습니다. 그렇다면 문제의 전체 오류 메시지를 추가하십시오. – furas
이 코드 부분 만'root = Tk()'와'Annotate (object)'클래스로 실행 했습니까? 그렇다면'root = Tk()'만 실행하고 클래스 사용법을 배워야합니다. – furas
실수 : 당신이 클래스 '주석'을 사용하여 객체를 만들지 않았으므로 파이썬은'__init__'에서 코드를 실행할 수 없습니다. – furas