matplotlib - 使用 matplotlib 更改子图的大小
问题描述
我正在尝试使用 matplotlib 绘制多个 rgb 图像
我正在使用的代码是:
import numpy as np
import matplotlib.pyplot as plt
for i in range(0, images):
test = np.random.rand(1080, 720,3)
plt.subplot(images,2,i+1)
plt.imshow(test, interpolation='none')
虽然作为缩略图,子图看起来很小我怎样才能让它们变大?我已经看到使用的解决方案
fig, ax = plt.subplots()
之前的语法,但不是 with plt.subplot
?
解决方案
plt.subplots
启动子图网格,同时plt.subplot
添加子图。因此,区别在于您是想立即开始绘制还是随着时间的推移填充它。既然您似乎事先知道要绘制多少张图像,我还建议您使用子图。
另请注意,您使用的方式会plt.subplot
在您实际使用的子图之间生成 empy 子图,这是它们如此小的另一个原因。
import numpy as np
import matplotlib.pyplot as plt
images = 4
fig, axes = plt.subplots(images, 1, # Puts subplots in the axes variable
figsize=(4, 10), # Use figsize to set the size of the whole plot
dpi=200, # Further refine size with dpi setting
tight_layout=True) # Makes enough room between plots for labels
for i, ax in enumerate(axes):
y = np.random.randn(512, 512)
ax.imshow(y)
ax.set_title(str(i), fontweight='bold')
推荐阅读
- javascript - 我想使用 res.sendfile 但路径不正确出现错误
- python - pyqt5 不同颜色的标记线
- node.js - NodeJS 内存泄漏
- android - 谷歌地图,带管理员 lte,android 和 IOS
- vb.net - TextChanged 和 switch 语句判断更改的文本框并重建图表数据并更新(索引超出范围)VB.Net
- java - 在java中使用'if'语句计算披萨价格
- xaml - WebView 在 Android 上显示,但在 iOS Xamarin 表单上不显示
- php - 如何使用laravel将Multipale数据存储在QR码中
- debugging - 为什么 SASM 的调试器不显示存储后更新的“结果”变量的值?
- javascript - 从 POST 请求中获取响应数据后 React JS & Axios Render