IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> Matplotlib绘图工具(四) -> 正文阅读

[Python知识库]Matplotlib绘图工具(四)

1、subplot多图和为一图显示

# 创建一个绘图窗口
plt.figure()

# 给定位置描述,图像分为2行2列,第一个位置显示某张图片
plt.subplot(2,2,1)
plt.plot([0,1], [0,1])


# 第二个位置显示某张图片
plt.subplot(222)
plt.plot([0,1], [0,1])

plt.subplot(223)
plt.plot([0,1], [0,1])

plt.subplot(224)
plt.plot([0,1], [0,1])

plt.show()

2、subplot分格显示

import matplotlib.gridspec as gridspec

plt.figure()

# 方法一subplot2grid,分成很多的ax,整个gride有3行3列,开始位置,跨度
ax1 = plt.subplot2grid((3,3),(0,0),colspan = 3, rowspan = 1)      # 图的位置
ax1.plot([1,2], [1,2])
ax1.set_title('ax1_title')
ax2 = plt.subplot2grid((3,3),(1,0),colspan = 2,)
ax3 = plt.subplot2grid((3,3),(2,0),rowspan = 2)
ax4 = plt.subplot2grid((3,3),(2,0))
ax5 = plt.subplot2grid((3,3),(2,1))


# 方法二:导入新包gridspec

plt.figure()
gs = gridespec.GridSpec(3,3)
ax1 = plt.subplot(gs[0,:])
# 到第二个截止
ax2 = plt.subplot(gs[1,:2])
# 1之后的全部
ax3 = plt.subplot(gs[1:,2])
ax4 = plt.subplot(gs[-1,0])
ax5 = plt.subplot(gs[-1,-2])


# 方法三:easy to define structure,返回值为图片,所有图像的格式,第一行所有axis,第二行所有axis
f, ((ax11,ax12), (ax21,ax22)) = plt.subplots(2,2,sharex = True, sharey = True)
ax11.scatter([1,2],[1,2])

plt.show()

3、图中图

fig = plt.figure()

# 绘制大图,图像的左右宽高为多少,百分比
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8
ax1 = fig.add_axes([left, bottom, width, height])
ax1.plot(x,y,'r')
ax1.set_xlabel('x')
ax1.set_ylabel('y')
ax1.set_title('title')


left, bottom, width, height = 0.2, 0.6, 0.25, 0.25
ax2 = fig.add_axes([left, bottom, width, height])
ax2.plot(y,x,'b')
ax2.set_xlabel('x')
ax2.set_ylabel('y')
ax2.set_title('title inside 1')

plt.axes([.6,0.2,0.25,0.25])
plt.plot(y[::-1],x,'g')
plt.xlabel('x')
plt.ylabel('y')
plt.title('title inside 2')

4、建立次坐标轴,共享同一个x轴

fig,ax1 = plt.subplots()


# 镜面反射该轴数据ax2的坐标轴是ax1的坐标轴反向的
ax2 = ax1.twinx()
ax1.plot(x,y1,'g-')
ax2.plot(x,y2,'b--')

ax1.set_xlabel('x data')
ax1.set_ylabel('y1', color = 'g')
ax2.set_ylabel('y2', color = 'b')

plt.show()

5.animation动画

interval隔多少毫秒更新一次,更新整张图的值,

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-08-07 21:45:13  更:2021-08-07 21:45:50 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/17 10:49:16-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码