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