• matplotlib的使用——picture in picture画中画的使用


    画中画显示的方法

    画中画显示呢,常常需要用到fig.add_axes()函数,其一共需要传入一个矩阵,矩阵中包含4个参数,分别为[left,bottom,width,height]。

    fig.add_axes()的使用方式

    fig.add_axes()函数传入参数的方式为:

    ax1 = fig.add_axes([left,bottom,width,height])
    

    其中left,bottom,width,height均代表百分比,代表其占整个图像的百分比。
    left为坐标轴最左侧举例边缘的百分比;
    bottom为坐标轴最下侧举例边缘的百分比;
    width代表左右坐标轴的距离;
    height代表上下坐标轴的距离;
    在这里插入图片描述

    应用示例

    import numpy as np
    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    
    x = [1,2,3,4,5,6,7]
    y = [7,6,5,4,3,2,1]
    
    left,bottom,width,height = 0.1,0.1,0.8,0.8
    
    # 添加最大的图像
    ax1 = fig.add_axes([left,bottom,width,height])
    ax1.plot(x,y,'r')
    ax1.set_title("ax1")
    
    # 添加第一幅画中画
    left,bottom,width,height = 0.15,0.15,0.3,0.3
    ax2 = fig.add_axes([left,bottom,width,height])
    ax2.plot(x,y,'r')
    ax2.set_title("ax2")
    
    # 添加第二幅画中画
    left,bottom,width,height = 0.55,0.55,0.3,0.3
    ax3 = fig.add_axes([left,bottom,width,height])
    ax3.plot(x,y,'r')
    ax3.set_title("ax3")
    
    plt.show()
    

    实现结果为

    在这里插入图片描述

    天道酬勤 循序渐进 技压群雄
  • 相关阅读:
    Nginx:缓存
    Nginx:静态资源压缩
    Cassandra:安装
    Cassandra:java客户端操作
    Postgresql:Centos7安装Postgresql
    Cassandra:cql基本操作
    Cassandra:cqlsh基本命令和cql
    Cassandra:基本概念
    Nginx:rewrite功能配置
    Nginx:负载均衡
  • 原文地址:https://www.cnblogs.com/wuyuan2011woaini/p/15681926.html
Copyright © 2020-2023  润新知