我在使用画图的时候发现matplotlib.pyplot.subplots返回的axes中,我设置了边框但最后一张子图却没有边框,希望能得到解答
def show_images(imgs, num_rows, num_cols, titles=None, scale=1.5): #@save
# 绘制图像列表
figsize = (num_cols * 1, num_rows * 1)
_, axes = plt.subplots(num_rows, num_cols, figsize=figsize)
# plt.tight_layout() # 调整整体空白
plt.axis('off')
plt.subplots_adjust(left=0, top=1, right=1, bottom=0, wspace=0, hspace=0)
axes = axes.flatten()
for i, (ax, img) in enumerate(zip(axes, imgs)):
if torch.is_tensor(img):
# 图片张量
ax.spines['top'].set_visible(True)
ax.spines['left'].set_visible(True)
ax.spines['right'].set_visible(True)
ax.spines['bottom'].set_visible(True)
ax.spines['left'].set_color('white')
ax.spines['left'].set_linewidth('1.0')
ax.spines['right'].set_color('white')
ax.spines['right'].set_linewidth('1.0')
ax.spines['top'].set_color('white')
ax.spines['top'].set_linewidth('1.0')
ax.spines['bottom'].set_color('white')
ax.spines['bottom'].set_linewidth('1.0')
ax.set_frame_on(True)
ax.imshow(img.numpy())
else:
# PIL图片
ax.spines.top.set_visible(True)
ax.spines.left.set_visible(True)
ax.spines.right.set_visible(True)
ax.spines.bottom.set_visible(True)
ax.spines['left'].set_color('white')
ax.spines['left'].set_linewidth('1.0')
ax.spines['right'].set_color('white')
ax.spines['right'].set_linewidth('1.0')
ax.spines['top'].set_color('white')
ax.spines['top'].set_linewidth('1.0')
ax.spines['bottom'].set_color('white')
ax.spines['bottom'].set_linewidth('1.0')
ax.set_frame_on(True)
ax.imshow(img.numpy())
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
"""if i == 0:
ax.text(-59, 37, 'scale', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-89, 105, 'vertical', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-93, 176, 'rotation', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-120, 243, 'horizontal', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 311, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 378, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 445, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 513, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 580, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')
ax.text(-56, 650, 'none', transform=ax.transData, fontsize=30, fontweight=500, fontfamily='Times New Roman')"""
plt.savefig('result.png')
plt.savefig('dSprites_traversals(tcvae).pdf')
return axes
其中img包括50张图片数据,num_rows=10, num_clos=5
最终的结果图如下