前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ig,ax = plt.subplots()

ig,ax = plt.subplots()

作者头像
狼啸风云
发布2022-07-22 13:43:04
2850
发布2022-07-22 13:43:04
举报
代码语言:javascript
复制
fig = plt.figure()
ax = fig.add_subplot(1,1,1)

fig, ax = plt.subplots(1,3),其中参数1和3分别代表子图的行数和列数,一共有 1x3 个子图像。函数返回一个figure图像和子图ax的array列表。 fig, ax = plt.subplots(1,3,1),最后一个参数1代表第一个子图。 如果想要设置子图的宽度和高度可以在函数内加入figsize值 fig, ax = plt.subplots(1,3,figsize=(15,7)),这样就会有1行3个15x7大小的子图。

控制子图

  • 方法1:通过plt控制子图
  • 方法2:通过ax控制子图
代码语言:javascript
复制
# Creates two subplots and unpacks the output array immediately
fig = plt.figure()
ax1, ax2 = fig.subplots(1, 2, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing Y axis')
ax2.scatter(x, y)

# Creates four polar axes, and accesses them through the
# returned array
axes = fig.subplots(2, 2, subplot_kw=dict(polar=True))
axes[0, 0].plot(x, y)
axes[1, 1].scatter(x, y)

(1) 单行单列,按照一维数组来表示

代码语言:javascript
复制
# 定义fig
fig = plt.figure()
# 建立子图
ax = fig.subplots(2,1)    # 2*1
# 第一个图为
ax[0].plot([1,2], [3,4])
# 第二个图为
ax[1].plot([1,2], [3,4])

(2) 多行多列,按照二维数组来表示

代码语言:javascript
复制
# 定义fig
fig = plt.figure()
# 建立子图
ax = fig.subplots(2,2)    # 2*2
# 第一个图为
ax[0,1].plot([1,2], [3,4])
# 第二个图为
ax[0,1].plot([1,2], [3,4])
# 第三个图为
ax[1,0].plot([1,2], [3,4])
# 第四个图为
ax[1,1].plot([1,2], [3,4])
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-07-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 控制子图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档