hands-on-data-analysis 第二单元 第四节数据可视化

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")

在这里插入图片描述

Learn how to create interactive and visually aesthetic plots using the Bokeh package in Python Key Features A step by step approach to creating interactive plots with Bokeh Go from nstallation all the way to deploying your very own Bokeh application Work with a real time datasets to practice and create your very own plots and applications Book Description Adding a layer of interactivity to your plots and converting these plots into applications hold immense value in the field of data science. The standard approach to adding interactivity would be to use paid software such as Tableau, but the Bokeh package in Python offers users a way to create both interactive and visually aesthetic plots for free. This book gets you up to speed with Bokeh - a popular Python library for interactive data visualization. The book starts out by helping you understand how Bokeh works internally and how you can set up and install the package in your local machine. You then use a real world data set which uses stock data from Kaggle to create interactive and visually stunning plots. You will also learn how to leverage Bokeh using some advanced concepts such as plotting with spatial and geo data. Finally you will use all the concepts that you have learned in the previous chapters to create your very own Bokeh application from scratch. By the end of the book you will be able to create your very own Bokeh application. You will have gone through a step by step process that starts with understanding what Bokeh actually is and ends with building your very own Bokeh application filled with interactive and visually aesthetic plots. What you will learn Installing Bokeh and understanding its key concepts Creating plots using glyphs, the fundamental building blocks of Bokeh Creating plots using different data structures like NumPy and Pandas Using layouts and widgets to visually enhance your plots and add a layer of interactivity Building and hosting applications on the Bokeh server Creating advanced plots using spatial data Who this book is for This book is well suited for data scientists and data analysts who want to perform interactive data visualization on their web browsers using Bokeh. Some exposure to Python programming will be helpful, but prior experience with Bokeh is not required. Table of Contents Bokeh installation and key concepts Plotting using glyphs Plotting with different data structures Using layouts for effective presentation Using annotations, widgets and visual attributes for visual enhancement Building and hosting applications using the Bokeh Server Advanced Plotting with Networks, Geo data, WebGL and Exporting plots The Bokeh Workflow: A case study
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈沧夜

打个赏,让我买瓶可乐喝呗~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值