🐍 파이썬 (Python) <matplotlib> + <tkinter> 그래프를 tkinter canvas 에 그려, 기능 추가하기 (1) - 일단은 tkinter의 기능들을 사용하기 위해서는 tkinter의 canvas로 그래프를 옮겨야한다. 기존의 matplotlib TKinter의 canvas에서 그래프 그리기. 기존의 matplotlib에서 제공하던 버튼들이 사라졌다. (축소 확대, 저장버튼들) 다음에는 TKinter를 이용하여 여러가지 기능들을 추가해보려고 한다. from matplotlib import pyplot as plt from matplotlib import animation import numpy as np import random import time # from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from matplotlib.figure import Figure import tkinter as Tk fig = plt.figure() #figure(도표) 생성 ax = plt.subplot(211, xlim=(0, 50), ylim=(0, 1024)) ax_2 = plt.subplot(212, xlim=(0, 50), ylim=(0, 512)) max_points = 50 max_points_2 = 50 line, = ax.plot(np.arange(max_points), np.ones(max_points, dtype=np.float)*np.nan, lw=1, c='blue',ms=1) line_2, = ax_2.plot(np.arange(max_points_2), np.ones(max_points, dtype=np.float)*np.nan, lw=1,ms=1) def init(): return line def init_2(): return line_2 def animate(i): y = random.randint(0,1024) old_y = line.get_ydata() new_y = np.r_[old_y[1:], y] line.set_ydata(new_y) print(new_y) return line def animate_2(i): y_2 = random.randint(0,512) old_y_2 = line_2.get_ydata() new_y_2 = np.r_[old_y_2[1:], y_2] line_2.set_ydata(new_y_2) print(new_y_2) return line_2 root = Tk.Tk() #추가 label = Tk.Label(root,text="라벨").grid(column=0, row=0)#추가 canvas = FigureCanvasTkAgg(fig, master=root) # canvas.get_tk_widget().grid(column=0,row=1) # anim = animation.FuncAnimation(fig, animate , init_func= init ,frames=200, interval=50, blit=False) anim_2 = animation.FuncAnimation(fig, animate_2 , init_func= init_2 ,frames=200, interval=10, blit=False) Tk.mainloop() 공유하기 URL 복사카카오톡 공유페이스북 공유엑스 공유 게시글 관리 구독하기newmon Contents 당신이 좋아할만한 콘텐츠 파이썬(Python) 기초 (14) 에러의 종류 , 에러 메시지 , 문법 에러 2019.12.16 파이썬 (python) if __name__ == "__main__" 무슨 뜻 ? 어떤 의미 ? 2019.12.12 파이썬 (python) - 모듈 , 패키지 ( module , package ) 생성 , import와 alias 2019.12.09 파이썬(Python) 기초 (13) 클래스의 상속, 다중상속 2019.12.09 댓글 2 + 이전 댓글 더보기