tf好朋友之matplotlib的使用——picture in picture画中画的使用

tf好朋友之matplotlib的使用——picture in picture画中画的使用

我还没有试过画中画是个什么东西呢,只听过看视频有画中画,那matplot中画中画长什么样呢?
在这里插入图片描述

画中画显示的方法

画中画显示呢,常常需要用到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()

实现结果为:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bubbliiiing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值