반응형

/*******************************************************************************************************************
-- Title : [Py2.7] Animation/Live Graph(애니메이션 그래프) w/ Matplotlib.pyplot
-- Reference : pythonprogramming.net
-- Key word : python 파이썬 pyplot matplotlib style animation FuncAnimation 애니메이션 차트 
                  애니메이션 그래프
*******************************************************************************************************************/


-- Chart



-- Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
 
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib import style
 
style.use('fivethirtyeight')
 
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
 
def animate(i):
    graph_data = open('D:\\PyProject\\20161216\\example.txt','r').read()
 
    print (graph_data)
 
    lines = graph_data.split('\n')
    xs = []
    ys = []
    for line in lines:
        if len(line) > 1:
            x, y = line.split(',')
            xs.append(x)
            ys.append(y)
    ax1.clear()
    ax1.plot(xs, ys)
 
# -- 실시간으로 텍스트 파일 변경 정보 가져와서 출력함
#    파일을 열고 계속 정보를 추가하면 그래프가 움직임.
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()
 
 
 

cs



-- Files

example.txt



반응형

+ Recent posts