[Python]plt.figure()、plt.subplot() 、plt.subplots()函数

plt.figure()

创建自定义图像

语法
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)
参数

num:图像编号或名称,数字为编号 ,字符串为名称
figsize:指定figure的宽和高,单位为英寸
dpi:指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是 21*30cm的纸张
facecolor:背景颜色
edgecolor:边框颜色
frameon:是否显示边框

实例
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(4,3),facecolor='blue')
plt.show()

plt.subplot()

创建单个子图

语法
subplot(numRows, numCols, plotNum)
参数

numRows:subplot行数
numCols:subplot列数
plotNum:指定创建的Axes对象所在的区域

实例
import numpy as np  
import matplotlib.pyplot as plt  
x = np.arange(0, 20)  
# 绘制图表样式为2X4的图片区域,用坐标表示为(1,1),(1,2),(2,1),(2,2),(3,1),(3,2),(4,1),(4,2),表示的坐标为(1,1),即第一行第一列的子图
plt.subplot(241)   
plt.plot(x,x)
plt.show()  
output

在这里插入图片描述

plt.subplots()

创建多个子图

语法、参数

同plt.subplot()

实例
import numpy as np  
import matplotlib.pyplot as plt

x = np.arange(0, 10)  
#划分子图
fig,axes=plt.subplots(2,1)
ax1=axes[0]
ax2=axes[1]

ax1.plot(x, x)  
ax2.plot(x, -x)
plt.show()
output

在这里插入图片描述

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值