python - 创建 3x3 matplotlib 子图,但在某些位置缺少图
问题描述
假设我有 6 个图,我想以通常的方式(plt.subplots 等)安排到一个子图设置中。
但是出于可视化原因,我需要按以下方式排列它们:
|1 0 0 |
|1 1 0 |
|1 1 1 |
其中 1 表示我想要一个情节,0 表示我不想要。我不完全确定如何使用 matplotlib 中的子图做到这一点。任何建议都会很棒-谢谢!
解决方案
使用Figure.add_gridspec
和Figure.add_subplot
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure(constrained_layout=True)
>>> gs = fig.add_gridspec(3, 3)
>>> axes = [fig.add_subplot(gs[x,y])
for x in range(3) for y in range(3) if x >= y]
>>> plt.show()
推荐阅读
- laravel - 获取用户所有付款的收入总和?
- json - 循环使用特定符号的 JSON 文件
- reactjs - TypeError:无法读取 null 的属性“querySelector”
- postgresql - postgreSQL 日志更改列
- javascript - discord.js embedMsg 没有定义?
- c# - DotNet 在同一本地服务器上显示不同的端口
- android - 无论如何,在 XML 中使可绘制透明?
- angularjs - angular js - 更改路径但不重新加载控制器
- python - 为什么跳跃不起作用在pygame中不起作用
- php - Laravel 文件系统磁盘无法在生产中工作