Python数据分析基础第二课—绘图库Matplotlib,从入魔到入佛!

极简编程,极简生活,简到极致,就是完美!

Python数据分析基础第二课—绘图库Matplotlib,绘制常用的直方图、折线图、饼图…… Lets go !

在这里插入图片描述

# 导入
from matplotlib import pyplot as plt
import numpy as np
# 1.方程直线图
x = np.arange(0, 11, 1)
y = 2*x + 1
plt.title(" y=2x+1 ")
plt.xlabel("x alias")
plt.ylabel("y alias")
plt.plot(x, y)
plt.show()

在这里插入图片描述

# 2.点图
x = np.arange(0, 11, 1)
y = x+1
plt.title(" y=x+1 ")
plt.xlabel("x alias")
plt.ylabel("y alias")
plt.plot(x, y, 'ob')
plt.show()

在这里插入图片描述

# 3.正弦波图
x3 = np.arange(0, 3 * np.pi, 0.1)
y3 = np.sin(x3)
y32 = np.cos(x3)

# 一页多图 subplot()
plt.subplot(1, 2, 1)
plt.plot(x3, y3)
plt.title(" y=sin(x) ")

plt.subplot(2, 2, 2)
plt.title(" y=cos(x) ")
plt.plot(x3, y32)

plt.show()

在这里插入图片描述

# 4.直方图
arr4 = np.asarray([1, 11, 22, 33, 32, 45, 90, 100, 44,
                  76, 23, 2, 3, 44, 44, 44, 22, 11])
plt.hist(arr4)
plt.title(" hist ")
plt.show()

在这里插入图片描述

# 5.折线图
x5 = np.arange(1, 9, 1)
y5 = np.asarray([1, 2, 4, 7, 9, 15,4,2])
plt.plot(x5, y5, 'g-.')
plt.show()

在这里插入图片描述

# 6.饼图

plt.figure(figsize=(6, 6))  # 将画布设定为正方形
explode = [0.01, 0.01, 0.01]  # 设定各项距离圆心n个半径
arr6 = np.asarray([2, 3, 5])

plt.pie(arr6, explode=explode, autopct='%1.1f%%')  # 绘制饼图
plt.title('饼图')

plt.show()

在这里插入图片描述


这期到这里了,下期结构化数据分析库Pandas,下期见,Byebye!
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

道-闇影

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值