-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
64 lines (56 loc) · 1.58 KB
/
tools.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
def f(n):
results = []
for i in xrange(6):
for j in xrange(6-i-1):
try:
results.append(n.compare_keeps(i,i+j+1))
except:
results.append(0)
return results
import matplotlib.pyplot as plt
def smart_plot(liste, x_list = None, figure = False, names = None,xlabel=None,ylabel=None,xlim=None,ylim=None, legend=None, legend_position=1):
color = ("r--", "b--", "g--", "y--", "o--")
if figure:
plt.figure(1)
nb_figure = len(liste)
for key in xrange(len(liste)):
plt.subplot(nb_figure, 1, key)
plt.plot(range(len(liste[key])), liste[key], color[0])
if names is not None:
plt.title(names[key])
else:
ax = plt.gca()
if x_list is None:
args = ()
kwargs = {}
label = None
for key in xrange(len(liste)):
if legend is not None:
kwargs = {"label":legend[key]}
args = (range(len(liste[key])), liste[key], color[key % len(color)])
plt.plot(*args,**kwargs)
else:
args = (x_list, liste, color[0])
plt.plot(*args)
if names is not None:
plt.title(names)
if xlabel is not None:
ax.set_xlabel(xlabel)
if ylabel is not None:
ax.set_ylabel(ylabel)
if xlim is not None:
ax.set_xlim(xlim)
if ylim is not None:
ax.set_ylim(ylim)
if legend is not None:
if legend_position==1:
loc = "upper right"
elif legend_position==2:
loc = "lower right"
elif legend_position==3:
loc = "lower left"
else:
loc = "upper left"
plt.legend(loc=loc)
plt.show()
return plt