当前位置:网站首页>hands-on-data-analysis 第二单元 第四节数据可视化
hands-on-data-analysis 第二单元 第四节数据可视化
2022-06-23 16:31:00 【沧夜2021】
hands-on-data-analysis 第二单元 第四节数据可视化
文章目录
1.简单绘图
1.1.导入库
#inline表示将图表嵌入到Notebook中
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
1.2.基本的绘图示例
import numpy as np
data = np.arange(10)
data
plt.plot(data)

1.3.子图示例
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.子图绘图示例
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--是绘制黑色分段线的选项
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选项
| 参数 | 描述 |
|---|---|
| nrows | 子图的行数 |
| ncols | 子图的列数 |
| sharex | 所有子图使用相同的x轴刻度(调整xlim会影响所有子图) |
| sharey | 所有子图使用相同的y轴刻度(调整ylim会影响所有子图) |
| subplot_kw | 传入add_subplot的关键字参数字典,用于生成子图 |
| **fig_kw | 在生成图片时使用的额外关键字参数,例如plt.subplot(2,2,figsize(8,6)) |
2.可视化展示泰坦尼克号数据集中男女中生存人数分布情况
sex = text.groupby('Sex')['Survived'].sum()
sex.plot.bar()
plt.title('survived_count')
plt.show()

3.可视化展示泰坦尼克号数据集中男女中生存人与死亡人数的比例图
text.groupby(['Sex','Survived'])['Survived'].count().unstack().plot(kind='bar',stacked='True')
plt.title('survived_count')
plt.ylabel('count')

4.可视化展示泰坦尼克号数据集中不同票价的人生存和死亡人数分布情况。
# 计算不同票价中生存与死亡人数 1表示生存,0表示死亡
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.可视化展示泰坦尼克号数据集中不同仓位等级的人生存和死亡人员的分布情况
# 1表示生存,0表示死亡
pclass_sur = text.groupby(['Pclass'])['Survived'].value_counts()
pclass_sur
import seaborn as sns
sns.countplot(x="Pclass", hue="Survived", data=text)

6.可视化展示泰坦尼克号数据集中不同年龄的人生存与死亡人数分布情况
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.可视化展示泰坦尼克号数据集中不同仓位等级的人年龄分布情况。
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")

边栏推荐
- Implementation of network data transmission by golang Gob
- Innovative technology leader! Huawei cloud gaussdb won the 2022 authoritative award in the field of cloud native database
- 数字经济加速落地,能为中小企业带来什么?
- 图扑软件数字孪生挖掘机实现远程操控
- Intel arc A380 graphics card message summary: the entry-level price products of running point and bright driving need to be optimized
- The R language uses the GT package and the gtextras package to display tabular data gracefully and beautifully: gt of the gtextras package_ The sparkline function visualizes the line plot of the group
- Importance and purpose of test
- ABAP随笔-程序优化笔记
- ABAP随笔-物料主数据界面增强
- Spdlog logging example - create a logger using sink
猜你喜欢

Apache基金会正式宣布Apache InLong成为顶级项目

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

How to use SQL window functions

stylegan1: a style-based henerator architecture for gemerative adversarial networks

Shushulang passed the listing hearing: the gross profit margin of the tablet business fell, and the profit in 2021 fell by 11% year-on-year

《MPLS和VP体系结构》

JS常见的报错及异常捕获

Tupu digital twin 3D wind farm, offshore wind power of smart wind power

QT当中的【QSetting和.ini配置文件】以及【创建Resources.qrc】

The summary of high concurrency experience under the billion level traffic for many years is written in this book without reservation
随机推荐
What can the accelerated implementation of digital economy bring to SMEs?
NPM install problem solving (NVM installation and use)
ABAP随笔-程序优化笔记
电感参数有哪些?怎么选择电感?
Date转换为LocalDateTime
Freemark uses FTL files to generate word
IFLYTEK neuroimaging disease prediction program!
How to use SQL window functions
谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
[solution] NPM warn config global ` --global`, `--local` are deprecated Use `--location=global`
The Google play academy team PK competition is in full swing!
移动云共筑信创云能力底座,助力中国信创产业发展
NLP paper reading | improving semantic representation of intention recognition: isotropic regularization method in supervised pre training
官方零基础入门 Jetpack Compose 的中文课程来啦
Robot Orientation and some misunderstandings in major selection in college entrance examination
Code implementation of golang binary search method
聚焦:ZK-SNARK 技术
ABAP essays - program optimization notes
ELK日志收集系统部署
leetcode:面試題 08.13. 堆箱子【自頂而下的dfs + memory or 自底而上的排序 + dp】