-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyQmt2.py
93 lines (77 loc) · 2.16 KB
/
PyQmt2.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 28 12:13:54 2016
@author: user11
"""
import pandas as pd
import numpy as np
import glob
import seaborn as sbn
import matplotlib.pyplot as plt
from scipy.stats import sem
path = 'Z:/RESULTATS/807677'
# path = r'C:/Users/user11.HPO-SAMAT/Pictures'
def scan(path, atr, key, size):
"""
Scan folder for **.x file** containing **string y**
"""
src = path + "/**/" + key +'.' + atr
liste = glob.glob(src)
print(src)
return liste
def file2df(elmnt):
data = pd.read_csv(elmnt, header=None,
sep='\t+',
index_col=False,)
data = data[data[3] == True]
b = {x: 'c_'+str(x) for x in data.columns}
data.rename(columns=b, inplace=True)
data = data.dropna()
return data
# %% chargement des données
a = scan(path, 'log', '*2016*', None)
dfs = []
for file in a:
try:
df = file2df(file)
df.c_6.astype(np.float)
df.c_5.astype(np.float)
dfs.append(df)
except:
print("error + "+file)
# %% formatage des données
data = pd.concat(dfs)
data.c_6 = data.c_6.astype(np.float)
data.c_5 = data.c_5.astype(np.float)
data.c_0 = pd.to_datetime(data.c_0)
data.c_0 = data.c_0.dt.week
week = data.c_0.unique()
week.sort()
# %% préparation des données
grouped = data.groupby('c_0', as_index=True)
mean = grouped.c_5.mean().get_values()
std = grouped.c_5.std().get_values()
xx = [x for x in range(len(mean))]
y = [x for x in grouped.size().index]
# %% plot
plt.style.use('seaborn-paper')
#plt.rcParams['figure.figsize']=(20,10)
#plt.rcParams['figure.fontsize']=20
plt.figure(1)
g1 = plt.plot(mean)
plt.fill_between(xx, mean-3*std,
mean+3*std, color="#3F5D7D")
plt.figure(2)
sbn.distplot(data.c_5)
# g2 = sbn.stripplot(data.c_5, jitter=True)
plt.figure(3)
sbn.tsplot(mean, time=week)
plt.figure(4)
sbn.violinplot(data.c_5, groupby=data.c_0)
plt.figure(5)
sbn.boxplot(data.c_5, groupby=data.c_0)
# g2.axes.set_xticks(np.linspace(3.95,4.10,16,endpoint=True))
# g2.axes.set_xlim(3.95,4.10)
#plt.plot(xx,6*std)
#sbn.plot(d)
#http://www.randalolson.com/2014/06/28/how-to-make-beautiful-data-visualizations-in-python-with-matplotlib/