当前位置:网站首页>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")

边栏推荐
- 接口的所有权之争
- Digital twin excavator of Tupu software realizes remote control
- leetcode:面試題 08.13. 堆箱子【自頂而下的dfs + memory or 自底而上的排序 + dp】
- 《MPLS和VP体系结构》
- R language uses the image of magick package_ The scale function resizes the image. You can customize the scaling from the angle of width or height
- What are the inductance parameters? How to choose inductance?
- Can the asemi fast recovery diodes RS1M, us1m and US1G be replaced with each other
- 千呼万唤,5G双卡双通到底有多重要?
- Six stone programming: the subtlety of application
- Implementation of golang bubble sort code
猜你喜欢

Implementation of golang bubble sort code

Rongyun: let the bank go to the "cloud" easily
![Leetcode: question d'entrevue 08.13. Empiler la boîte [DFS en haut + mémoire ou tri en bas + DP]](/img/22/220e802da7543c2b14b7057e4458b7.png)
Leetcode: question d'entrevue 08.13. Empiler la boîte [DFS en haut + mémoire ou tri en bas + DP]
![[untitled] Application of laser welding in medical treatment](/img/c5/9c9edf1c931dfdd995570fa20cf7fd.png)
[untitled] Application of laser welding in medical treatment

【网络通信 -- WebRTC】WebRTC 源码分析 -- 接收端带宽估计

JS常见的报错及异常捕获

The evolution of social structure and capital system brought about by the yuan universe

What can the accelerated implementation of digital economy bring to SMEs?

Robot Orientation and some misunderstandings in major selection in college entrance examination

How to make sales management more efficient?
随机推荐
I successfully joined the company with 27K ByteDance. This interview notes on software testing has benefited me for life
【网络通信 -- WebRTC】WebRTC 源码分析 -- PacingController 相关知识点补充
Golang data type diagram
Digital twin excavator of Tupu software realizes remote control
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
ABP framework - data access infrastructure (Part 2)
Date to localdatetime
如何选择示波器?这10点一定要考虑!
Case analysis of camera power supply disturbed, seriously affecting image quality
读书郎通过上市聆讯:平板业务毛利率走低,2021年利润同比下滑11%
Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
Practice sharing of chaos engineering in stability management of cloud native Middleware
数据库 实验二 查询
[network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
ABAP essay - material master data interface enhancement
Lamp architecture that your girlfriend can read
NLP paper reading | improving semantic representation of intention recognition: isotropic regularization method in supervised pre training
R language uses colorblinr package to simulate color blind vision, and uses edit to visualize the image of ggplot2_ The colors function is used to edit and convert color blindness into visual results
ERP管理系统的重要性
炒股买股票需要怎么选择呢?安全性不错的?