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控制子图

# 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) 单行单列,按照一维数组来表示

# 定义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])
# 设置子图之间的间距,默认值为1.08
plt.tight_layout(pad=1.5)

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

# 定义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])

最新文章

  1. Spell-DBC
  2. php://input
  3. 关于SilverLight
  4. C 到C++的升级
  5. jquery动态创建节点
  6. 5 Tips for creating good code every day; or how to become a good software developer
  7. Apache Kafka源码分析 - kafka controller
  8. hadoop2.0 和1.0的区别
  9. 小心!#define max(a,b) a>b?a:b
  10. C# 每天温习一点(IEnumerable<TSource>)
  11. ecshop后台admin文件夹任意更改名
  12. 工资表的生成、显示、修改工资,应用transactionscope 分布式事务
  13. [转载]date命令时间转换
  14. Android 中 ListView 常用属性合集
  15. Servlet(二)GenericServlet
  16. sql server中的索引详情
  17. 【firefox】关闭firefox缓存
  18. 【UML 建模】状态图介绍
  19. python简单爬虫技术
  20. RobotFramework自动化测试框架-DatabaseLibrary库的使用(对数据库的操作)

热门文章

  1. VUE实战项目-数据转换之道
  2. css总结4:input 去掉外边框,placeholder的字体颜色、字号
  3. Java 数据结构之双链表
  4. C# How To Read .xlsx Excel File With 3 Lines Of Code
  5. javascript高级程序设计读书笔记----函数表达式
  6. VS Code 运行html文件
  7. visual studio installer 卸载时不能删除安装目录问题
  8. javascript 文件的操作
  9. javascript js自执行函数
  10. tomcat 安装与使用!