Python数据分析 三剑客篇(三)matplotlib全网最混介绍

Matpoltlib

数据可视化基础,相对而言,这个库没有前两个库那么复杂,主要功能就是绘制图形,直观的表达数据之间的联系
简单折线图展示

import pandas as pd
task=pd.read_csv("/Users/a/Desktop/Titanic/gendermodel.csv")#读取数据
print(task.head(6))#打印前六行
import matplotlib.pyplot as plt
first_six=task[0:12]
plt.plot(first_six["PassengerId"],first_six["Survived"])#plot()中,前一个参数表示x轴,后一个表示y轴
plt.xlabel("Passenger ID")#x轴命名
plt.ylabel("Survived")#y轴命名
plt.title("task")#表格标题
plt.show()

绘制出的折线图如下:

在这里插入图片描述

创建画布和创建子图

fig=plt.figure()#创建画布
ax1=fig.add_subplot(2,2,1)#2*2矩阵的第一个,说明add_subplot(行,列,第几个)
ax2=fig.add_subplot(2,2,2)#2*2矩阵的第二个
ax3=fig.add_subplot(2,2,4)#2*2矩阵的第四个
ax1.plot(first_six["PassengerId"],first_six["Survived"])
ax2.plot(first_six[“PassengerId"],first_six["Survived"],c='red')#指定线条颜色为红色

plt.show()

结果如下:
在这里插入图片描述
其余用法不做过多解释,更多在数据分析实例里面体现

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值