subplots、add_subplots、math.floor()、math.ceil()函数

math.floor()函数

math.floor(x)函数为向下取整,返回一个小于等于x的最大整数

math.ceil()函数

math.ceil(x)函数为向上取整,返回一个大于等于x的最小整数

figure语法及操作

1. 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:是否显示边框

2. subplots语法

subplot(nrows,ncols,sharex,sharey,subplot_kw,**fig_kw)
在这里插入图片描述【例子】:

import numpy as np
import matplotlib.pyplot as plt
 
x = np.arange(0, 100)
#划分子图
fig,axes=plt.subplots(2,2)
ax1=axes[0,0]
ax2=axes[0,1]
ax3=axes[1,0]
ax4=axes[1,1]
 
#作图1
ax1.plot(x, x)
#作图2
ax2.plot(x, -x)
#作图3
ax3.plot(x, x ** 2)
ax3.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)
#作图4
ax4.plot(x, np.log(x))
plt.show()

3. add_subplots语法

add_subplot()的作用与subplot一样,用于新增子图。具体如下:

#新建figure对象
fig=plt.figure()
#新建子图1,(2,2,1)表示创建2x2子图中的第一个
ax1=fig.add_subplot(2,2,1)

【例子】:

    import numpy as np
    import matplotlib.pyplot as plt
    x = np.arange(0, 100)
    #新建figure对象
    fig=plt.figure()
    #新建子图1
    ax1=fig.add_subplot(2,2,1)
    ax1.plot(x, x)
    #新建子图2
    ax3=fig.add_subplot(2,2,2)
    ax3.plot(x, x ** 2)
    ax3.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)
    #新建子图3
    ax4=fig.add_subplot(2,2,3)
    ax4.plot(x, np.log(x))
    plt.show()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值