可以看一下是否没有创建figure,并为之设置figsize大小。
images_test = (images_test + 1.0) / 2.0
for n in range(num_clusters):
#origal
pylab.subplot(2, num_clusters, n+1)
pylab.imshow(images_test[n*num_plots_per_cluster].reshape((image_width, image_height)), interpolation="none")
pylab.gray()
pylab.axis("off")
#reconsruct
image = images_test_reconstruction[n * num_plots_per_cluster].reshape((image_width, image_height))
pylab.subplot(2, num_clusters, num_clusters+n+1)
pylab.imshow(image.data, interpolation="none")
pylab.gray()
pylab.axis("off")
fig = pylab.gcf()
fig.set_dpi(720)
pylab.savefig("clusters.png")
pylab.close()
以上代码结果为
pylab.figure(figsize=(38,4))
images_test = (images_test + 1.0) / 2.0
for n in range(num_clusters):
#origal
pylab.subplot(2, num_clusters, n+1)
pylab.imshow(images_test[n*num_plots_per_cluster].reshape((image_width, image_height)), interpolation="none")
pylab.gray()
pylab.axis("off")
#reconsruct
image = images_test_reconstruction[n * num_plots_per_cluster].reshape((image_width, image_height))
pylab.subplot(2, num_clusters, num_clusters+n+1)
pylab.imshow(image.data, interpolation="none")
pylab.gray()
pylab.axis("off")
fig = pylab.gcf()
fig.set_dpi(720)
pylab.savefig("clusters.png")
pylab.close()
设置figure大小后结果为