• 技术文章 >Python技术 >Python基础教程

    python中subplot函数怎么画图?

    小妮浅浅小妮浅浅2021-07-20 09:42:58原创16703

    说明

    1、调用subplot()函数可以创建子图,程序可以在子图上绘制。subplot(nrows、ncols、index、**kwargs)函数的nrows参数指定将数据图区域分成多少行,ncols参数指定将数据图区域分成多少列,index参数指定获得多少区域。

    2、subplot()函数还支持直接输入一个三位数的参数,其中第一位数是nrows参数;第二位数是ncols参数;第三位数是index参数。

    参数

    nrows: subplot的行数

    ncols: subplot的列数

    sharex :所有subplot应该使用相同的X轴刻度(调节xlim将会影响所有的subplot)

    sharey: 所有subplot应该使用相同的Y轴刻度(调节ylim将会影响所有的subplot)

    subplot_kw: 用于创建各subplot的关键字字典

    **fig_kw: 创建figure时的其他关键字

    实例

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    import numpy as np

    import matplotlib.pyplot as plt

    x = np.arange(0, 100)

    #作图1

    plt.subplot(2,2,1)  #等效于plt.subplot(221)

    plt.plot(x, x)

    #作图2

    plt.subplot(2,2,2)

    plt.plot(x, -x)

    #作图3

    plt.subplot(2,2,3)

    plt.plot(x, x ** 2)

    plt.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)

    #作图4

    #plt.subplot(224)

    #plt.plot(x, np.log(x))

    plt.show()

    以上就是python中subplot函数画图的方法,希望对大家有所帮助。更多Python学习指路:python基础教程

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    专题推荐:python subplot
    上一篇:python中figure()函数画两张图 下一篇:python局部作用域是什么

    相关文章推荐

    • python WSGI规范是什么• python整数的进制转换• python中Queue如何通信• python中进程池Pool的初始化• python Pool常用函数有哪些• python中figure()函数画两张图

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网