• 【python】多图绘制(matplotlib)


    安装模块

    pip install matplotlib
    

    规则划分

    多图分别绘制在MN列的网格中,且单图都各占一个单元格。

    import matplotlib.pyplot as plt
    plt.subplot(221, fc='r')
    plt.subplot(222, fc='g')
    plt.subplot(223, fc='b')
    plt.subplot(224, fc='c')
    plt.show()
    

    在这里插入图片描述
    共绘制4个图,每个图占1个单元格:创建2x2的网格,正好容下。

    不规则划分

    多图分别绘制在MN列的网格中,但有的单图需要占多个单元格。

    import matplotlib.pyplot as plt
    plt.subplot(221, fc='r')
    plt.subplot(222, fc='g')
    plt.subplot(212, fc='b')
    plt.show()
    

    在这里插入图片描述
    共绘制3个图,蓝图由于某种原因需要占2个单元格:

    假设将蓝图拆开成两个图,就可以按2x2划分,红图绘制在221的位置,绿图绘制在222的位置。

    假设将红图和绿图合并为一个图,就可以按2x1划分,蓝图绘制在212的位置。


    只要掌握了这种假设法,即使更复杂的不规则划分也能实现:

    import matplotlib.pyplot as plt
    plt.subplot(321, fc='r')
    plt.subplot(322, fc='g')
    plt.subplot(312, fc='b')
    plt.subplot(325, fc='r')
    plt.subplot(326, fc='g')
    plt.show()
    

    在这里插入图片描述

    温馨提示

    fc参数是subplot方法中设置背景颜色的,更多关于subplot方法的参数和实例可以参考官方文档。

    引用参考

    https://www.cnblogs.com/xiaoboge/p/9683056.html
    https://matplotlib.org/api/_as_gen/matplotlib.pyplot.savefig.html?highlight=savefig#matplotlib.pyplot.savefig
    
  • 相关阅读:
    MarkDown使用教程
    B+树详解
    B-树(B树)详解
    SQL优化之limit 1
    mysql explain用法和结果的含义
    MySQL 常用内置函数与所有内置函数
    Mac os 相关查找命令
    数据库——自然连接、内连接、外连接(左外连接、右外连接,全连接)、交叉连接
    sql语句执行顺序
    有三个线程,怎么让他们按顺序执行?
  • 原文地址:https://www.cnblogs.com/ghgxj/p/14219090.html
Copyright © 2020-2023  润新知