-
Notifications
You must be signed in to change notification settings - Fork 1
/
interconnector.py
95 lines (70 loc) · 2.23 KB
/
interconnector.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
import csv
import numpy as np
import pickle
import bokeh
import matplotlib.pyplot as plt
import pandas as pd
import marketUtils
# Generates data for plotting, returns as dict, is then plotted when key_event function is called.
def chartFlowVsPrice(nem, flows):
plots = []
states = {
'nsw': {'color': '#DC6BAD',},
'qld': {'color': '#8C7AA9',},
'vic': {'color': '#7192BE',},
'sa': {'color': '#E88D67',},
'tas': {'color': '#2F394D',}
}
attributes = list(flows[list(flows)[0]])
attributes.sort()
for interconnectorAttribute in attributes:
for state in list(states):
print "charting "+state+" "+ interconnectorAttribute
flow = []
price = []
for time in list(nem):
price.append(nem[time][state]['price'])
flow.append(flows[time][interconnectorAttribute])
symbol = 'o'
if "Export" in interconnectorAttribute:
symbol = '^'
elif "Import" in interconnectorAttribute:
symbol = 'v'
plots.append({
'x': flow,
'y': price,
'xlabel': interconnectorAttribute,
'ylabel': state+' price',
'title': interconnectorAttribute +' vs '+state.upper()+' Spot Price',
'symbol': symbol,
'color':states[state]['color']
})
return plots
# Handles using arrow keys to move through different subplots.
# Adapted from this StackOverflow question http://stackoverflow.com/questions/18390461/scroll-backwards-and-forwards-through-matplotlib-plots
curr_plt_index = 0
plots = []
def key_event(e):
global curr_plt_index
if e.key == "right":
curr_plt_index = curr_plt_index + 1
elif e.key == "left":
curr_plt_index = curr_plt_index - 1
else:
return
curr_plt_index = curr_plt_index % len(plots)
ax.cla()
ax.plot(plots[curr_plt_index]['x'], plots[curr_plt_index]['y'], plots[curr_plt_index]['symbol'], color=plots[curr_plt_index]['color'])
plt.ylabel(plots[curr_plt_index]['ylabel'])
plt.xlabel(plots[curr_plt_index]['xlabel'])
plt.title(plots[curr_plt_index]['title'])
fig.canvas.draw()
nem = marketUtils.getNem()
flows = marketUtils.getInterconnectorFlows()
plots = chartFlowVsPrice(nem, flows)
fig = plt.figure()
fig.canvas.mpl_connect('key_press_event', key_event)
ax = fig.add_subplot(111)
plt.title("Use the < > arrow keys to scroll through plots.")
plt.show()