출처 : http://josephmr.com/realtime-arduino-sensor-monitoring-with-matplotlib/
import matplotlib.pyplot as pltimport matplotlib.animation as animfrom collections import dequeimport randomMAX_X = 100 #width of graphMAX_Y = 1000 #height of graph# intialize line to horizontal line on 0line = deque([0.0]*MAX_X, maxlen=MAX_X)def update(fn, l2d):#simulate data from serial within +-5 of last datapointdy = random.randint(-5, 5)#add new point to dequeline.append(line[MAX_X-1]+dy)# set the l2d to the new line coords# args are ([x-coords], [y-coords])l2d.set_data(range(-MAX_X/2, MAX_X/2), line)fig = plt.figure()# make the axes revolve around [0,0] at the center# instead of the x-axis being 0 - +100, make it -50 - +50# ditto for y-axis -512 - +512a = plt.axes(xlim=(-(MAX_X/2),MAX_X/2), ylim=(-(MAX_Y/2),MAX_Y/2))# plot an empty line and keep a reference to the line2d instancel1, = a.plot([], [])ani = anim.FuncAnimation(fig, update, fargs=(l1,), interval=50)plt.show()
'Python' 카테고리의 다른 글
웹서버 만들기 (0) | 2015.02.27 |
---|---|
(펌)파이썬을 배우는 최고의 방법 (0) | 2015.02.10 |
python 파이썬 문법 공부하기 좋은 사이트 (0) | 2015.02.08 |