matplotlib中画图的方式

matplotlib中画图的方式

1、matplotlib中,figure是最基础的对象,是一块总的画布,可以对画布es小背景等设置(画板/背景)

2、几乎所有的画图都是在axes上完成的(灵活的子图)

3、subplot是特殊的axes(对齐坐标的子图)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KTbIbCgQ-1626249305408)(https://ewr1.vultrobjects.com/imgspice2/000/005/005/807_9c0_d02.png)]

fig = plt.figure()
# C1
ax1 = fig.add_subplot(221)
ax1.plot([1,2,3])
print(type(ax1))

<class ‘matplotlib.axes._subplots.AxesSubplot’>

fig = plt.figure()
# C2
ax2 = plt.subplot(221) #底层调用add_subplot
ax2.plot([1,2,3])
print(type(ax2))

<class ‘matplotlib.axes._subplots.AxesSubplot’>

# C3
fig, ax = plt.subplots(2,2) #创建了figure和axes对象
ax3 = ax[0,0]
ax3.plot([1,2,3])
print(type(ax3))

<class ‘matplotlib.axes._subplots.AxesSubplot’>

fig = plt.figure()
#C4
ax4 = fig.add_axes([0.1,0.1,0.8,0.8])
ax4.plot([1,2,3])
print(type(ax4))
#这个例子展示了axes与subplot的关系——subplot是axes的特殊

<class ‘matplotlib.axes._axes.Axes’>

参考资料

https://www.zhihu.com/question/51745620

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值