当前位置:网站首页>Hands on data analysis unit 2 section 4 data visualization
Hands on data analysis unit 2 section 4 data visualization
2022-06-23 17:17:00 【Cangye 2021】
hands-on-data-analysis Unit two Section 4 data visualization
List of articles
- hands-on-data-analysis Unit two Section 4 data visualization
- 1. Simple drawing
- 2. Visually display the distribution of survival numbers between men and women in the Titanic data set
- 3. Visually display the proportion of survival and death of men and women in the Titanic data set
- 4. Visually display the distribution of survival and death toll of people with different ticket prices in the Titanic data set .
- 5. Visually display the distribution of survival and death of people at different positions in the Titanic data set
- 6. Visually display the distribution of life and death at different ages in the Titanic data set
- 7. Visually display the age distribution of people in different positions in the Titanic dataset .
1. Simple drawing
1.1. Import library
#inline Indicates embedding a chart into Notebook in
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
1.2. Basic drawing examples
import numpy as np
data = np.arange(10)
data
plt.plot(data)

1.3. Examples of subgraphs
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
ax4 = fig.add_subplot(2,2,4)

1.4. Example of subgraph drawing
fig = plt.figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
#k-- Is an option to draw black segment lines
plt.plot(np.random.randn(50).cumsum(),'k--')
_ = ax1.hist(np.random.randn(100),bins=20,color='k',alpha=0.3)
ax2.scatter(np.arange(30),np.arange(30)+3*np.random.randn(30))

1.5. pyplot.subplots Options
| Parameters | describe |
|---|---|
| nrows | Row number of subgraphs |
| ncols | Number of columns in a subgraph |
| sharex | All subgraphs use the same x Axis scale ( adjustment xlim Will affect all subgraphs ) |
| sharey | All subgraphs use the same y Axis scale ( adjustment ylim Will affect all subgraphs ) |
| subplot_kw | Pass in add_subplot Keyword parameter Dictionary of , Used to generate subgraphs |
| **fig_kw | Additional keyword parameters used when generating images , for example plt.subplot(2,2,figsize(8,6)) |
2. Visually display the distribution of survival numbers between men and women in the Titanic data set
sex = text.groupby('Sex')['Survived'].sum()
sex.plot.bar()
plt.title('survived_count')
plt.show()

3. Visually display the proportion of survival and death of men and women in the Titanic data set
text.groupby(['Sex','Survived'])['Survived'].count().unstack().plot(kind='bar',stacked='True')
plt.title('survived_count')
plt.ylabel('count')

4. Visually display the distribution of survival and death toll of people with different ticket prices in the Titanic data set .
# Calculate the number of survival and death in different ticket prices 1 It means survival ,0 It means death
fare_sur = text.groupby(['Fare'])['Survived'].value_counts().sort_values(ascending=False)
fare_sur
fig = plt.figure(figsize=(20, 18))
fare_sur.plot(grid=True)
plt.legend()
plt.show()

5. Visually display the distribution of survival and death of people at different positions in the Titanic data set
# 1 It means survival ,0 It means death
pclass_sur = text.groupby(['Pclass'])['Survived'].value_counts()
pclass_sur
import seaborn as sns
sns.countplot(x="Pclass", hue="Survived", data=text)

6. Visually display the distribution of life and death at different ages in the Titanic data set
facet = sns.FacetGrid(text, hue="Survived",aspect=3)
facet.map(sns.kdeplot,'Age',shade= True)
facet.set(xlim=(0, text['Age'].max()))
facet.add_legend()

7. Visually display the age distribution of people in different positions in the Titanic dataset .
text.Age[text.Pclass == 1].plot(kind='kde')
text.Age[text.Pclass == 2].plot(kind='kde')
text.Age[text.Pclass == 3].plot(kind='kde')
plt.xlabel("age")
plt.legend((1,2,3),loc="best")

边栏推荐
- JS常见的报错及异常捕获
- Codeforces Round #620 (Div. 2)ABC
- R language plot visualization: plot visualization adds bar chart with error bars with plot in R
- 美团三面:聊聊你理解的Redis主从复制原理?
- ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比
- 图扑数字孪生 3D 风电场,智慧风电之海上风电
- Jetpack compose and material you FAQs
- Importance and purpose of test
- ABAP essay - material master data interface enhancement
- 股票网上开户及开户流程怎样?在线开户安全么?
猜你喜欢

Comparison of asemi Schottky diode and ultrafast recovery diode in switching power supply

How to use SQL window functions

How to make sales management more efficient?

图扑软件数字孪生挖掘机实现远程操控

Network remote access raspberry pie (VNC viewer)

Jetpack Compose 与 Material You 常见问题解答

网络远程访问树莓派(VNC Viewer)

Jetpack compose and material you FAQs

官方零基础入门 Jetpack Compose 的中文课程来啦!

Tensorrt Paser loading onnx inference use
随机推荐
ELK日志收集系统部署
JS common error reporting and exception capture
How can the points mall make profits
How to choose an account opening broker? Is it safe to open an account online now?
元宇宙带来的社会结构和资本制度演变
QT当中的【QSetting和.ini配置文件】以及【创建Resources.qrc】
MySQL事务及其特性与锁机制
ADC digital DGND, analog agnd mystery!
Date to localdatetime
[network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
Tensorrt Paser loading onnx inference use
华为手机通过adb安装APK提示“签名不一致,该应用可能已被修改”
ABAP随笔-物料主数据界面增强
Get first and last days by year
bypassuac提权
How to select securities companies? Is it safe to open a mobile account?
NPM install problem solving (NVM installation and use)
什么是抽象类?怎样定义抽象类?
How important is 5g dual card dual access?
QT布局管理器【QVBoxLayout,QHBoxLayout,QGridLayout】