我使用以下代码绘制一些大小为512x512的整数矩阵。但是,无论matplotlib
和Top
的长度如何,保存的数字的分辨率始终为800x600(Bottom
默认值?)(参见下图)。现在怎么能强迫Top
和Bottom
的单个图像的分辨率完全等于相应矩阵的大小?
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
def compare_data(to_fname, Top, Bottom, m1, m2):
fig = plt.figure()
grid_top = ImageGrid(fig, 211, nrows_ncols = (1, len(Top)),
cbar_location = "right",
cbar_mode="single",
cbar_pad=.2)
grid_bot = ImageGrid(fig, 212, nrows_ncols = (1, len(Top)),
cbar_location = "right",
cbar_mode="single",
cbar_pad=.2)
for n in xrange(len(Top)):
im1 = grid_top[n].imshow(Top[n], vmin=0, vmax=m1, cmap=pylab.cm.seismic)
grid_top[n].axis('off')
im2 = grid_bot[n].imshow(Bottom[n], vmin=-m2, vmax=m2, cmap=pylab.cm.seismic)
grid_bot[n].axis('off')
grid_top.cbar_axes[0].colorbar(im1)
grid_bot.cbar_axes[0].colorbar(im2)
#plt.show()
plt.savefig(to_fname)
plt.close()