栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

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

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/307514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号