-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path22Plot3.py
120 lines (73 loc) · 2.22 KB
/
22Plot3.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# -*- coding: utf-8 -*-
#Heat Map
#A heatmap contains values representing various shades of the same colour for each value to be plotted. Usually the darker shades of the chart represent higher values than the lighter shade. For a very different value a completely different colour can also be used.
#The below example is a two-dimensional plot of values which are mapped to the indices and columns of the chart.
from pandas import DataFrame
import matplotlib.pyplot as plt
#data for 4 columns
data=[{2,3,4,1},{6,3,5,2},{6,3,5,4},{3,7,5,4},{2,8,1,5}]
data
Index= ['I1', 'I2','I3','I4','I5'] #Index values
Cols = ['C1', 'C2', 'C3','C4'] #columns
df = DataFrame(data, index=Index, columns=Cols)
df
plt.pcolor(df)
plt.show()
import seaborn as sns
sns.heatmap(df)
#1-darkest, 8 - lightest
#https://matplotlib.org/3.1.0/gallery/images_contours_and_fields/image_annotated_heatmap.html
#https://seaborn.pydata.org/generated/seaborn.heatmap.html
import numpy as np
import seaborn as sns
import pandas as pd
uniform_data = np.random.rand(10, 10)
uniform_data
df = pd.DataFrame(uniform_data)
df
ax = sns.heatmap(uniform_data)
ax= sns.heatmap(df)
df
fig, axis = plt.subplots() # il me semble que c'est une bonne habitude de faire supbplots
heatmap = axis.pcolor(uniform_data, cmap=plt.cm.Blues) # heatmap contient les valeurs
plt.colorbar(heatmap)
#Histogram - Matplotlib
##-----------------------------
#%
#mtcars data
from pydataset import data
mtcars = data('mtcars')
mtcars.head(5)
mtcars
mtcars.dtypes
#which are continuous variables
mtcars[['mpg','wt','hp','disp']]. head()
dat = mtcars['mpg']
np.mean(dat)
np.median(dat)
np.std(dat)
len(dat)
test = np.random.normal(19.2, 5.932, 100 )
plt.hist(dat, bin=5)
plt.hist(test, bins=10)
np.mean(test)
np.median(test)
import matplotlib.pyplot as plt
import numpy as np
plt.hist(mtcars.mpg)
plt.hist(mtcars['mpg'])
#other options
plt.hist(mtcars['mpg'], alpha=0.4)
plt.hist(mtcars.wt)
mtcars.wt.mean()
mtcars.wt.max()
mtcars.wt.min()
ls=np.linspace(mtcars.wt.min(),mtcars.wt.max(), num=5)
ls
np.histogram(mtcars.wt, bins=ls)
plt.hist(mtcars.wt)
import seaborn as sns
sns.distplot(mtcars['mpg'], kde=True)
data_2 = np.random.normal(90, 20, 200)
data_2
sns.distplot(data_2, kde=True)