摘要:我想使用Matplotlib.tight_layout()
自动优化包含任意数量2D numpy.array
子图形的图形布局
示例: 下面是一个示例(可以从http://www.filedropper.com/fmap访问数据)。我想绘制CNN层的特征图(稍后我想使其自动化,以便代码可以绘制来自任何模型的任何层的特征图)。在这里,我仅显示一层的代码进行演示:
fmap.shape # (1, 64, 64, 128)
square1 = int(round(math.sqrt(fmap.shape[-1])/8)*8) # 8
square2 = int(fmap.shape[-1]/square1) # 16
ix = 1
for _ in range(square1):
for _ in range(square2):
# specify subplot and turn of axis
ax = plt.subplot(square1, square2, ix)
ax.set_xticks([])
ax.set_yticks([])
# plot filter channel in grayscale
plt.imshow(fmap[0, :, :, ix-1], cmap='gray')
ix += 1
# show the figure
plt.tight_layout()
plt.show()
可以使用^{} 设置地物布局参数
基本代码
完整代码
为了避免多次尝试设置
left
、top
等的值,我建议您绘制一个图形,按下配置子图按钮:并手动更改这六个参数的值,直到找到满足您要求的配置。此时,您可以通过使用
subplots_adjust
的代码直接设置这六个值相关问题 更多 >
编程相关推荐