修复了ImageGrid中的分辨率图像

时间:2015-11-24 19:34:06

标签: python matplotlib

我使用以下代码绘制一些大小为512x512的整数矩阵。但是,无论matplotlibTop的长度如何,保存的数字的分辨率始终为800x600(Bottom默认值?)(参见下图)。现在怎么能强迫TopBottom的单个图像的分辨率完全等于相应矩阵的大小?

   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()

enter image description here enter image description here

0 个答案:

没有答案