-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotLogs.py
More file actions
60 lines (50 loc) · 1.7 KB
/
plotLogs.py
File metadata and controls
60 lines (50 loc) · 1.7 KB
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
'''
Functions for plotting log entries
Can be called while, at the end or after a session to visualize
e.g. training progress.
'''
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import numpy as np
#TODO: formatting the plot, remove doublin code
#TODO: legend for multiple plots
#if the abscissa is just the numbering of the entries
#@param logs a dictionary with arrays as values
#@param keys is an array of dictornary keys whose values ought to be plotted
#if None: plot all keys
def plotDefault(destinyFile, logs, keys = None, xLabel = '', yLabel = ''):
k = keys
if k is None:
k = []
for c in logs:
k += [c]
for c in k:
plt.plot(logs[c])
plt.xlabel(xLabel)
plt.ylabel(yLabel)
fig = plt.gcf()
fig.set_size_inches(40,10)
plt.savefig(destinyFile + '.png')
plt.clf()
#if the abscissa has custom values like time samples
#@param logs a dictionary with arrays as values
#@param abcissaKey dictionary key for the abscissa values
#@param keys is an array of dictornary keys whose values ought to be plotted
#if None: plot all keys except abscissaKey
def plotCustom(destinyFile, logs, abscissaKey, keys = None, xLabel = '', yLabel = ''):
k = keys
if k is None:
k = []
for c in logs:
assert np.shape(logs[abscissaKey]) == np.shape(logs[c]), "Array of abscissa and ordinate values are not of the same shape!"
if c != abscissaKey:
k += [c]
for c in k:
plt.plot(logs[abscissaKey], logs[c])
plt.xlabel(xLabel)
plt.ylabel(yLabel)
fig = plt.gcf()
fig.set_size_inches(40,10)
plt.savefig(destinyFile + '.png')
plt.clf()