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

matplotlib.pyplot一图多张表

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

matplotlib.pyplot一图多张表

matplotlib.pyplot一图多张表
  • 1. plt.subplot(x, y, n)和plt.subplots(x, y)
  • 2. 创建一图多表

1. plt.subplot(x, y, n)和plt.subplots(x, y)

【plt.subplot(x, y, n)】其中 x 代表生成表的行数,y 代表生成表的列数,n 代表第几张表
比如plt.subplot(3, 4, n)生成12张表

import matplotlib.pyplot as plt
# 循环创建12张表
for i in range(1, 13):
    plt.subplot(3, 4, i)
plt.show()

或者使用plt.subplots(3, 4)

import matplotlib.pyplot as plt
# 直接创建12张表
plt.subplots(3,4)
plt.show()

二者结果一致:

2. 创建一图多表
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
# 使用系统文字,用来正常显示中文标签
plt.rcParams['font.sans-serif'] = ['SimHei']
# x 轴数据
x = [1, 2, 3, 4]
# 创建第一张表数据位置在图的(1,1)位置
plt.subplot(2, 2, 1)
# y 轴数据
y = [8, 7, 6, 5]
plt.plot(x, y, c='r')
# 单张表标题
plt.title("表1")

# 创建第二张表数据位置在图的(1,2)位置
plt.subplot(2, 2, 2)
y = [2, 4, 6, 8]
plt.plot(x, y, c='b')
# 单张表标题
plt.title("表2")

# 创建第三张表数据位置在图的(2,1)位置
plt.subplot(2, 2, 3)
y = [3, 4, 5, 7]
plt.plot(x, y, c='y')
# 单张表标题
plt.title("表3")

# 创建第四张表数据位置在图的(2,2)位置
plt.subplot(2, 2, 4)
# 这里更改了表4 x 轴数据
x = [2, 4, 6, 8]
y = [9, 7, 3, 1]
plt.plot(x, y, c='g')
# 单张表标题
plt.title("表4")

# 多表图标题
plt.suptitle("四张表")
# 绘图
plt.show()

运行结果:

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

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

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