-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvop2pdf_make_graph.py
49 lines (38 loc) · 1.5 KB
/
vop2pdf_make_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
# native
from math import ceil, log
#imported
from matplotlib import pyplot as plt
# Retourne la puissance de 2 la plus proche pour que le graph soit bien alligné
def power_log(x):
return 2**(ceil(log(x, 2)))
def make_graph(title, horodating, data_daily, data_total, save_path):
# Crée un subplot pour pouvoir instancier deux mesures sur l'axe Y
fig, ax1 = plt.subplots(figsize=((len(data_daily) / 5) + 10, 12))
plt.title(title)
# Premier label vertical | axe Y
color = '#ff5b0c'
ax1.bar(horodating, data_daily, color=color, width=0.5)
ax1.tick_params(axis='y', labelcolor=color)
ax1.set_ylabel('Consommation par heure (Mo)', color=color)
# Etabli la hauteur maximale de l'échelle
ax1.set_ylim(top=2000)
# Ajoute une grille sur l'axe horizontal
ax1.grid(axis='x')
# Label horizontal | axe X
ax1.set_xlabel('Horodatage')
ax1.set_xticks(horodating)
ax1.set_xticklabels(horodating, rotation=90)
# Instantie un deuxième graph partageant le même axe X
ax2 = ax1.twinx()
# Second label vertical | axe Y
color = '#0097ff'
coeff = power_log(data_total[-1]/ 2000) * 2000
ax2.set_ylim(top=coeff if coeff >= 2000 else 2000)
ax2.set_ylabel('Consommation totale (Mo)', color=color)
ax2.plot(horodating, data_total, color=color, linewidth=1)
ax2.tick_params(axis='y', labelcolor=color)
ax2.grid(axis='y')
fig.tight_layout()
plt.savefig("{}/{}.{}".format(save_path, title, extension))
plt.close()
extension = "svg"