-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
66 lines (50 loc) · 1.7 KB
/
graph.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# coding=utf-8
#Copyright (C) 2016 Viktor Horsmanheimo <[email protected]>
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or (at
#your option) any later version.
#This program is distributed in the hope that it will be useful, but
#WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#General Public License for more details.
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib.dates as mdates
import datetime
from yahoo_finance import Currency
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
currencies = Currency('usdeur')
spot = 1
xar=[]
yar=[]
ymin = float(currencies.get_rate())-0.0005
ymax = ymin + 0.0010
def animate(i):
global xar, yar, ymin, ymax
#gets the course
currencies.refresh()
y = currencies.get_rate()
x = datetime.datetime.now()
#makes the y axis larger if needed
if float(y) > ymax:
ymax = float(y)+0.0005
if float(y) < ymin:
ymin = float(y) - 0.0005
print str(x) +": " + str(y)
xar.append(x)
yar.append(float(y))
if len(xar) > 240:
del xar[0]
del yar[0]
ax1.clear()
ax1.yaxis.grid(True)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%H.%M.%S'))
ax1.plot(xar,yar)
plt.autoscale('both')
plt.gcf().autofmt_xdate()
ax1.set_ylim([ymin,ymax])
plt.title("Course right now: "+str(y))
ani = animation.FuncAnimation(fig,animate, interval=2000)
plt.show()