In [26]:
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import time
import pandas as pd

In [74]:
DB = pd.read_csv('005930.csv')

In [75]:
DB


Out[75]:
Date Open High Low Close Volume Adj Close MA240 DIFF
0 2011-01-03 955000 966000 950000 958000 264800 924155.80 NaN NaN
1 2011-01-04 956000 961000 949000 958000 274200 924155.80 NaN NaN
2 2011-01-05 955000 955000 942000 942000 335700 908721.05 NaN NaN
3 2011-01-06 942000 949000 923000 930000 387200 897144.99 NaN NaN
4 2011-01-07 915000 929000 914000 921000 462700 888462.94 NaN NaN
5 2011-01-10 918000 928000 909000 917000 366500 884604.25 NaN NaN
6 2011-01-11 917000 922000 908000 913000 391000 880745.56 NaN NaN
7 2011-01-12 914000 933000 914000 930000 409700 897144.99 NaN NaN
8 2011-01-13 949000 949000 917000 922000 564700 889427.61 NaN NaN
9 2011-01-14 928000 934000 915000 933000 307600 900039.00 NaN NaN
10 2011-01-17 945000 951000 940000 949000 411600 915473.76 NaN NaN
11 2011-01-18 950000 981000 949000 969000 592600 934767.20 NaN NaN
12 2011-01-19 979000 1000000 966000 997000 666800 961778.01 NaN NaN
13 2011-01-20 987000 990000 979000 982000 304800 947307.93 NaN NaN
14 2011-01-21 976000 984000 970000 971000 333300 936696.54 NaN NaN
15 2011-01-24 968000 983000 966000 971000 272100 936696.54 NaN NaN
16 2011-01-25 972000 990000 971000 975000 279400 940555.23 NaN NaN
17 2011-01-26 985000 999000 980000 998000 267000 962742.68 NaN NaN
18 2011-01-27 995000 1002000 991000 994000 307300 958884.00 NaN NaN
19 2011-01-28 998000 1014000 990000 1010000 382300 974318.75 NaN NaN
20 2011-01-31 1009000 1010000 981000 981000 428200 946343.26 NaN NaN
21 2011-02-01 982000 995000 979000 983000 269300 948272.60 NaN NaN
22 2011-02-07 1002000 1004000 972000 972000 485000 937661.21 NaN NaN
23 2011-02-08 970000 974000 959000 961000 609600 927049.82 NaN NaN
24 2011-02-09 973000 973000 951000 960000 419600 926085.15 NaN NaN
25 2011-02-10 960000 965000 935000 936000 613300 902933.02 NaN NaN
26 2011-02-11 935000 943000 913000 915000 529700 882674.91 NaN NaN
27 2011-02-14 928000 955000 925000 953000 391300 919332.44 NaN NaN
28 2011-02-15 963000 970000 947000 958000 362100 924155.80 NaN NaN
29 2011-02-16 952000 970000 945000 945000 303600 911615.07 NaN NaN
... ... ... ... ... ... ... ... ... ...
1150 2015-06-18 1259000 1279000 1251000 1265000 164900 1265000.00 1299120.836083 -34120.836083
1151 2015-06-19 1266000 1278000 1260000 1266000 141800 1266000.00 1298880.711875 -32880.711875
1152 2015-06-22 1291000 1296000 1276000 1281000 127400 1281000.00 1298662.021958 -17662.021958
1153 2015-06-23 1309000 1328000 1291000 1321000 203100 1321000.00 1298630.531542 22369.468458
1154 2015-06-24 1300000 1311000 1291000 1302000 203900 1302000.00 1298560.940167 3439.059833
1155 2015-06-25 1290000 1303000 1269000 1269000 213900 1269000.00 1298284.037083 -29284.037083
1156 2015-06-26 1252000 1290000 1252000 1278000 206900 1278000.00 1298044.634000 -20044.634000
1157 2015-06-29 1269000 1285000 1256000 1281000 230300 1281000.00 1297805.411208 -16805.411208
1158 2015-06-30 1276000 1285000 1266000 1268000 197400 1268000.00 1297397.037792 -29397.037792
1159 2015-07-01 1268000 1302000 1259000 1295000 166400 1295000.00 1297064.205250 -2064.205250
1160 2015-07-02 1286000 1304000 1285000 1299000 164400 1299000.00 1296961.581042 2038.418958
1161 2015-07-03 1287000 1294000 1267000 1268000 142600 1268000.00 1296939.225250 -28939.225250
1162 2015-07-06 1253000 1260000 1223000 1230000 201900 1230000.00 1296655.871875 -66655.871875
1163 2015-07-07 1220000 1259000 1220000 1240000 249500 1240000.00 1296418.291708 -56418.291708
1164 2015-07-08 1240000 1251000 1232000 1239000 235600 1239000.00 1296242.250000 -57242.250000
1165 2015-07-09 1230000 1265000 1226000 1265000 280600 1265000.00 1296215.607333 -31215.607333
1166 2015-07-10 1257000 1266000 1248000 1259000 191400 1259000.00 1296328.227500 -37328.227500
1167 2015-07-13 1250000 1272000 1245000 1266000 153400 1266000.00 1296387.882917 -30387.882917
1168 2015-07-14 1265000 1270000 1221000 1225000 399700 1225000.00 1296293.131292 -71293.131292
1169 2015-07-15 1225000 1238000 1224000 1235000 167400 1235000.00 1296248.259458 -61248.259458
1170 2015-07-16 1223000 1287000 1223000 1282000 223400 1282000.00 1296411.540667 -14411.540667
1171 2015-07-17 1300000 1311000 1278000 1305000 297200 1305000.00 1296670.655208 8329.344792
1172 2015-07-20 1291000 1304000 1273000 1275000 128900 1275000.00 1296849.942042 -21849.942042
1173 2015-07-21 1275000 1277000 1247000 1263000 194000 1263000.00 1296962.802583 -33962.802583
1174 2015-07-22 1244000 1260000 1235000 1253000 268300 1253000.00 1297005.250458 -44005.250458
1175 2015-07-23 1244000 1253000 1234000 1234000 208900 1234000.00 1297075.302500 -63075.302500
1176 2015-07-24 1227000 1238000 1224000 1229000 196500 1229000.00 1297075.242375 -68075.242375
1177 2015-07-27 1229000 1247000 1228000 1230000 243000 1230000.00 1297157.373750 -67157.373750
1178 2015-07-28 1224000 1251000 1219000 1230000 267600 1230000.00 1297264.144542 -67264.144542
1179 2015-07-29 1250000 1275000 1231000 1263000 274600 1263000.00 1297475.562792 -34475.562792

1180 rows × 9 columns

Plot a live graph from a text file


In [78]:
fig = plt.figure()
chart = fig.add_subplot(1,1,1)

def animate(i):
    pullData = open('sample.txt', 'r').read()
    dataArray = pullData.split('\n')
    xar =[]
    yar =[]
    for eachLine in dataArray:
        if len(eachLine) > 1:
            x,y = eachLine.split(',')
            xar.append(int(x))
            yar.append(int(y))
    chart.clear()
    chart.plot(xar, yar)
ani = animation.FuncAnimation(fig, animate, interval = 1000)
plt.show()

Plot a live graph from CSV


In [79]:
fig = plt.figure()
chart = fig.add_subplot(1,1,1)
DB = pd.read_csv('005930.csv')

def animate(i):
    frame = 240 + i
    index = DB.index[:frame]
    Value = DB['Adj Close'][:frame]
    #MA30  =  DB['MA30'][:frame]
    MA240 =  DB['MA240'][:frame]
    chart.clear()
    chart.plot(index, Value, 'g')
    #chart.plot(index, MA30, 'r')
    chart.plot(index, MA240, 'b')
    
ani = animation.FuncAnimation(fig, animate, interval = 10)
plt.show()

In [ ]: