diff options
author | Denise sur Lya <sekhmet@lya> | 2020-06-14 23:20:48 +0200 |
---|---|---|
committer | Denise sur Lya <sekhmet@lya> | 2020-06-14 23:20:48 +0200 |
commit | 5679dfd03c9761283e3a36d6d09798aaa334e1e9 (patch) | |
tree | ad22413283e2f9662af4bc526b6de119e270dae0 /trace_courbe.py | |
download | oms-5679dfd03c9761283e3a36d6d09798aaa334e1e9.tar.gz oms-5679dfd03c9761283e3a36d6d09798aaa334e1e9.tar.zst oms-5679dfd03c9761283e3a36d6d09798aaa334e1e9.zip |
Création du dépôt, site à peu près fonctionnel
Diffstat (limited to 'trace_courbe.py')
-rw-r--r-- | trace_courbe.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/trace_courbe.py b/trace_courbe.py new file mode 100644 index 0000000..c15960f --- /dev/null +++ b/trace_courbe.py | |||
@@ -0,0 +1,96 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | # -*- coding: utf-8 -*- | ||
3 | from configuration import * | ||
4 | from gestionOMS import * | ||
5 | from gestion_unites import * | ||
6 | import matplotlib.pyplot as plt | ||
7 | |||
8 | def cree_figure(conf,l_jours,l_poids,liste_err): | ||
9 | |||
10 | |||
11 | if conf["maxi"] == 0: | ||
12 | if l_jours != []: | ||
13 | jour_maxi = max(l_jours)# pas la peine d'aller très au delà du jour max | ||
14 | jour_maxi = int(jour_maxi* 1.1)+3 # on rajoute un peu | ||
15 | else: | ||
16 | jour_maxi = int(6*jours_dans_mois) # si pas de données, arbitrairement on met ça | ||
17 | else: | ||
18 | jour_maxi = conf["maxi"]+1 | ||
19 | |||
20 | jour_maxi = min(jour_maxi,jours_maxi_courbe) | ||
21 | |||
22 | if conf["unite"] == "": | ||
23 | conf["unite"] = choix_unite(jour_maxi) | ||
24 | |||
25 | l_jours_conv = convertit_tableau(l_jours,conf["unite"],liste_err) | ||
26 | # Attention, comme les jours commencent à partir de 0, faut enlever 1 pour avoir la borne... | ||
27 | age_maxi = convertitunite(jour_maxi-1,conf["unite"],liste_err) | ||
28 | |||
29 | |||
30 | titre = "Courbe de poids OMS" | ||
31 | |||
32 | if conf["typecourbe"] == "P": | ||
33 | # percentiles | ||
34 | liste_data_labels = liste_data_labels_p | ||
35 | if conf["sexe"] == "M": | ||
36 | fichier_oms = f_poids_perc_garcon | ||
37 | titre += " (percentiles, garçon)" | ||
38 | else: | ||
39 | fichier_oms = f_poids_perc_fille | ||
40 | titre += " (percentiles, fille)" | ||
41 | elif conf["typecourbe"] == "Z": | ||
42 | liste_data_labels = liste_data_labels_z | ||
43 | if conf["sexe"] == "G": | ||
44 | fichier_oms = f_poids_z_garcon | ||
45 | titre += " (moyenne et écarts-types, garçon)" | ||
46 | else: | ||
47 | fichier_oms = f_poids_z_fille | ||
48 | titre += " (moyenne et écarts-types, fille)" | ||
49 | |||
50 | # Si y'a un nom on met "courbe de machin" | ||
51 | if conf["nom"] !="": | ||
52 | titre += " de " +conf["nom"] | ||
53 | |||
54 | |||
55 | # convertir les unités | ||
56 | |||
57 | #### On extrait les données des courbes, et on convertit les jours dans l'unité voulues | ||
58 | t = lire_fichier_csv(fichier_oms) | ||
59 | coljour = convertit_tableau(extraire_colonne(t,0,jour_maxi),conf["unite"],liste_err) | ||
60 | |||
61 | |||
62 | #### La figure | ||
63 | fig = plt.figure(num=None, figsize=(conf["largeur"], conf["hauteur"]), dpi=100, facecolor='w', edgecolor='k') | ||
64 | |||
65 | for (i,label,couleur) in liste_data_labels: | ||
66 | plt.plot(coljour,extraire_colonne(t,i,jour_maxi),label=label,color=couleur) | ||
67 | |||
68 | # On extrait la valeur min et la valeur max des poids | ||
69 | (colonne_min,_,_) = liste_data_labels[0] | ||
70 | (colonne_max,_,_) = liste_data_labels[-1] | ||
71 | |||
72 | poids_min = min(extraire_colonne(t,colonne_min,jour_maxi)) | ||
73 | poids_max = max(extraire_colonne(t,colonne_max,jour_maxi)) | ||
74 | if l_jours != []: | ||
75 | poids_min = min(min(l_poids),poids_min) | ||
76 | poids_max = max(max(l_poids),poids_max) | ||
77 | # On ajuste un peu ces min et max | ||
78 | # min : valeur min -1kg | ||
79 | poids_min = max(0,poids_min-1) | ||
80 | #max : +5% | ||
81 | poids_max = poids_max * 1.05 | ||
82 | |||
83 | if l_jours != []: | ||
84 | plt.plot(l_jours_conv,l_poids,label=conf["nom"],color="black",marker='o') | ||
85 | |||
86 | plt.xlabel("Âge en "+conf["unite"]) | ||
87 | plt.ylabel("Poids en kg") | ||
88 | plt.title(titre) | ||
89 | plt.axis([0,age_maxi,poids_min,poids_max]) | ||
90 | |||
91 | if conf['legende']=="oui": | ||
92 | plt.legend(loc=conf['positionlegende']) | ||
93 | plt.grid(conf["grille"]=="oui") | ||
94 | |||
95 | fig.tight_layout() | ||
96 | return fig \ No newline at end of file | ||