12.子图布局,嵌套

import numpy as np
import matplotlib.pyplot as plt
# 不用打imshow也能显示
%matplotlib inline 

子图布局

# 3行3列,第二个参数是在什么位置
ax1 = plt.subplot2grid((3,3), (0,0))
ax2 = plt.subplot2grid((3,3), (0,1))
ax3 = plt.subplot2grid((3,3), (1,0))
ax4 = plt.subplot2grid((3,3), (1,1))
ax5 = plt.subplot2grid((3,3), (0,2), rowspan=2) # 占用多行
ax6 = plt.subplot2grid((3,3), (2,0), colspan=3) # 占用多列

请添加图片描述

子图嵌套

x = np.linspace(0,10,1000)
y2 = np.sin(x**2)
y1 = x**2

# 主轴
fig, ax1 = plt.subplots()
left, bottom, width, height = [0.22,0.45,0.3,0.35]
# 嵌套一个子轴
ax2 = fig.add_axes([left,bottom,width,height])

ax1.plot(x,y1)
ax2.plot(x,y2)
[<matplotlib.lines.Line2D at 0x26272f307b8>]

请添加图片描述

  • 第二种子图嵌套
from mpl_toolkits.axes_grid.inset_locator import inset_axes

fig, ax1 = plt.subplots(figsize=(20,20))
ax1.bar(range(10),np.random.randn(10))
ax2 = inset_axes(ax1, width=6, height=6, loc=5)
ax2.plot([1,2,3],[2,3,4])
[<matplotlib.lines.Line2D at 0x26273030748>]

请添加图片描述


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值