-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsing_Seaborn.py
87 lines (55 loc) · 3.55 KB
/
Using_Seaborn.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
#SEABORN
seabornData=sns.load_dataset('planets') #tips,planets is the buil-in data set in seaborn
print(seabornData.head()) #to print data
plt.show(sns.distplot(seabornData['orbital_period'],bins=10))
#bins value is if less then broader graph appear
#distplot(like histogram) show along with kde ,you can set its value to false to remove
#joinplot
#best for large dataset
plt.show(sns.jointplot(x='orbital_period',y='mass',data=seabornData)) #scatter dots
plt.show(sns.jointplot(x='orbital_period',y='mass',data=seabornData,kind='hex',color='red')) #hex like honeycomb structure
plt.show(sns.jointplot(x='mass',y='distance',data=seabornData,kind='kde'))
#pairplot
plt.show(sns.pairplot(seabornData,palette='coolwarm'))#it takes time in loading if data is large
seabornData2=sns.load_dataset('tips')
print(seabornData2.head())
plt.show(sns.pairplot(seabornData2,hue='tip',palette='coolwarm'))
#rugplot
plt.show(sns.rugplot(seabornData['mass']))
#CategoricalPlot
#Bar & Countplot
plt.show(sns.barplot(x='sex',y='size',data=seabornData2))#notworking
plt.show(sns.countplot(x='sex',data=seabornData2)) #same as barplot,y-axis counts number of occurences
plt.show(sns.countplot(x='year',data=seabornData))
#Boxplot
plt.show(sns.boxplot(x='day',y='total_bill',hue='smoker'data=seabornData2,palette='cool')) #it shows quartiles,outliers
plt.show(sns.boxplot(x='method',y='year',data=seabornData,palette='pastel'))
#violinplot
plt.show(sns.violinplot(x='method', y='year', data=seabornData, palette='pastel'))#violin,boxplot shows separate graphs for each category like one for smokers and other for non-smokers
plt.show(sns.violinplot(x='day',y='total_bill',hue='smoker',split=True,data=seabornData2,palette='cool')) #split shows 1figure instead of 2
#StripPlot
plt.show(sns.stripplot(x='method', y='year', data=seabornData, palette='pastel'))
plt.show(sns.stripplot(x='day',y='total_bill',hue='smoker',data=seabornData2,palette='cool'))
plt.show(sns.stripplot(x='day',y='total_bill',hue='smoker',split=True,data=seabornData2,palette='cool'))
#SwarmPlot
plt.show(sns.swarmplot(x='day', y='total_bill', data=seabornData2, palette='cool'))
#combination of violin and stripplot
#FactorPlot
#it is the most preferable plot
plt.show(sns.factorplot(x='day',y='total_bill',hue='sex',kind='violin',data=seabornData2,palette='cool'))
#MatrixPlots
plt.show(sns.heatmap(seabornData.corr(),annot=True,cmap='coolwarm'))#it shows data in matrix form ,relation of each col with row's element by indicating different colors,annot shows the value range of colors
#you can add linewidth and linecolor to have a clear view
plt.show(sns.heatmap(seabornData.corr(),annot=True,linecolor='white',linewidths=3,cmap='coolwarm'))
#GridPlot
g=sns.PairGrid(seabornData,palette='coolwarm')
#arrangement must be the same as below
g.map_diag(sns.distplot )
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)
plt.show()
#FacetGrid
#it shows written values of smoker(yes,no) and time(lunch,dinner)
grid=sns.FacetGrid(data=seabornData2,col='time',row='smoker')
grid.map(sns.distplot,'total_bill')
plt.show()