-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxg_plot.py
57 lines (48 loc) · 1.82 KB
/
xg_plot.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
import matplotlib.pyplot as plt
import numpy as np
import tkinter
import matplotlib
matplotlib.use('TkAgg')
import psycopg2
# CONNECT TO POSTGRES DB #
try:
connection = psycopg2.connect(user = <insert username>,
password = <insert password>,
host = <insert sql server addr>,
port = <insert sql server port number>,
database = <insert database name>)
#Create cursor object. This will allow us to interact with the database and execute commands
cursor = connection.cursor()
# Print PostgreSQL version
cursor.execute("SELECT version();")
print("You are connected to the database ahlxgf")
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
for i in range(0,5):
#set the table name here
table_name = "ahlxgcalc"+str(i)
#Grab every xG row/datapoint from the database
cursor.execute("SELECT * FROM %s;" % table_name)
records = cursor.fetchall()
#Create numpy array that will be populated by our records
#shape = (rows,columns) in our case rows are the y's and columns are the x's
rows = 297
cols = 301
A = np.ndarray(shape=(rows,cols), dtype=float)
for record in records:
#A[x][y] = xG
A[record[0],record[1]] = record[2]
print("Array element (%i,%i) is %6.5f" % (record[0],record[1],record[2]))
plt.xlabel('Distance between the boards')
plt.ylabel('Distance from net')
i = str(i-2)
title = 'xGF for AHL shots at Strength %s' % i
plt.title(title)
im = plt.imshow(A, cmap='hot')
plt.colorbar(im)
plt.show()
#closing database connection.
if(connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")