Professional Documents
Culture Documents
5.datavisulation: 0.0.1 Type of Graphs
5.datavisulation: 0.0.1 Type of Graphs
DataVisulation
1
plt.rcParams['ytick.labelsize'] = 15
plt.rcParams['figure.dpi'] = 300
plt.show()
2
0.2 Histogram
[27]: tip = sns.load_dataset('tips')
[28]: tip.head()
3
[33]: sns.lineplot(x=range(tip.shape[0]), y='total_bill', data=tip, color='cyan')
plt.show()
4
[42]: India = np.random.normal(140, 10, 100)
USA = np.random.normal(130, 20, 100)
plt.ylabel("Height")
plt.legend()
plt.show()
5
[159]: fig, ax = plt.subplots()
sns.distplot(tip['total_bill'], ax=ax, bins=30)
plt.show()
6
[166]: fig, ax = plt.subplots()
sns.distplot(tip['total_bill'], ax=ax, bins=30, kde=False,
hist_kws={ 'ec':'silver', 'color':'gold'}, rug=True,
rug_kws={'color':'cyan'})
plt.show()
7
[59]: plt.boxplot(tip['total_bill'], showmeans=True,
showfliers=False, showcaps=False, showbox=False)
plt.show()
8
[70]: plt.boxplot(tip['total_bill'], showmeans=True,
flierprops={'markeredgecolor':'r', 'markerfacecolor': 'g', 'markersize':
,→10})
plt.show()
9
[77]: plt.boxplot(tip['total_bill'], showmeans=True,
flierprops={'markeredgecolor':'r'},
capprops={'color':'gold', 'linewidth': 3},
whiskerprops={'color': 'cyan', 'lw':2})
plt.show()
10
whiskerprops={'color': 'cyan', 'lw':2},
notch=True,
boxprops={'color': 'y'})
plt.show()
11
[90]: plt.boxplot(tip['total_bill'], showmeans=True,patch_artist=True,
flierprops={'markeredgecolor':'r'},
capprops={'color':'gold', 'linewidth': 3},
whiskerprops={'color': 'cyan', 'lw':2},
notch=True,
boxprops={'color': 'y'},
medianprops={'color':'white', 'lw': 3}
)
plt.show()
12
[119]: plt.boxplot(tip['total_bill'], showmeans=True,patch_artist=True,
flierprops={'markeredgecolor':'r'},
capprops={'color':'gold', 'linewidth': 3},
whiskerprops={'color': 'cyan', 'lw':2},
notch=True,
boxprops={'color': 'y'},
medianprops={'color':'white', 'lw': 3, 'ls':'--'},
meanprops={'markeredgecolor': 'white', 'marker': 'D', 'markerfacecolor':
,→ 'red',
'markersize':10}
)
plt.show()
13
plt.legend()
plt.show()
ax.set_xticks([1, 2])
ax.set_xticklabels(['India', 'USA'])
ax.set_ylabel('Height')
ax.set_xlabel('Country')
p['boxes'][0].set_color('blue')
p['boxes'][1].set_color('red')
ax.plot([], [], 'b-', label='India', lw=10)
ax.plot([], [], 'r-', label='USA', lw=10)
ax.legend(loc=10)
plt.show()
14
[173]: male = tip[tip['sex'] == 'Male']['total_bill']
female = tip[tip['sex']=='Female']['total_bill']
[174]: male.head()
[174]: 1 10.34
2 21.01
3 23.68
5 25.29
6 8.77
Name: total_bill, dtype: float64
[175]: female.head()
[175]: 0 16.99
4 24.59
11 35.26
14 14.83
16 10.33
Name: total_bill, dtype: float64
15
p['boxes'][1].set_color('red')
ax.plot([], [], 'b-', label='Male', lw=10)
ax.plot([], [], 'r-', label='Female', lw=10)
ax.legend(loc=10)
plt.show()
16
[184]: sns.boxplot('sex', 'total_bill', data=tip, notch=True,
hue='smoker', showmeans=True)
plt.show()
17
[191]: sns.violinplot('sex', 'total_bill', data=tip,hue='smoker')
plt.show()
18
[205]: sns.stripplot('sex', 'total_bill', data=tip,hue='smoker')
plt.show()
plt.show()
19
[199]: sns.kdeplot(tip.total_bill, tip.tip)
sns.rugplot(tip.total_bill, color='g')
sns.rugplot(tip.tip, color='b', vertical=True)
plt.show()
20
[208]: plt.scatter('total_bill','tip', data=tip)
plt.xlabel('Total Bill')
plt.ylabel("Tip")
plt.show()
21
[213]: print(np.corrcoef(tip.total_bill, tip.tip))
[[1. 0.67573411]
[0.67573411 1. ]]
[215]: mpg.head()
[221]: mpg.shape
22
[221]: (398, 9)
[234]: display.Image("https://www.oreilly.com/library/view/introduction-to-machine/
,→9781449369880/assets/malp_01in02.png",
height=300, width=500)
[234]:
23
[230]: iris = sns.load_dataset('iris')
[235]: iris.head()
24
[238]: np.corrcoef(iris.sepal_length, iris.sepal_width)
[247]: tip.sex[:5]
[247]: 0 Female
1 Male
2 Male
3 Male
4 Female
Name: sex, dtype: category
Categories (2, object): [Male, Female]
25
[264]: sns.scatterplot('total_bill', 'tip', hue='sex', data=tip)
plt.show()
26
[260]: color = list(map(lambda b: 'red' if b else '#eeeeee', (tip.tip > 5)))
[262]: mpg.head()
27
[262]: mpg cylinders displacement horsepower weight acceleration \
0 18.0 8 307.0 130.0 3504 12.0
1 15.0 8 350.0 165.0 3693 11.5
2 18.0 8 318.0 150.0 3436 11.0
3 16.0 8 304.0 150.0 3433 12.0
4 17.0 8 302.0 140.0 3449 10.5
28
bar, pie, matplot
[284]: sns.get_dataset_names()
The code that caused this warning is on line 376 of the file
C:\Anaconda3\lib\site-packages\seaborn\utils.py. To get rid of this warning,
pass the additional argument 'features="lxml"' to the BeautifulSoup constructor.
gh_list = BeautifulSoup(http)
[284]: ['anscombe',
'attention',
'brain_networks',
'car_crashes',
'diamonds',
'dots',
'exercise',
'flights',
'fmri',
'gammas',
'geyser',
'iris',
29
'mpg',
'penguins',
'planets',
'tips',
'titanic']
[ ]:
30