title: How do I set image axis range by using mataplotlib.imsave
body: <p>I generated an RGB image which is in pandas.DataFrame type. The image could be showed well by using matplotlib.pyplot.imshow(). Now I want to save the image to local disk.</p>
  
  <p>I skimmed the docs of matplotlib and found that ply.imsave() could do this. But imsave() don't have a parameter that could set the axis range. </p>
  
  <p>I tried plt.axis() but it doesn't work. Any tips here please?</p>
  
  <p>The code is below:</p>
  
  <pre><code>def _load_img(self, df):
      imgUnpadded = np.zeros((3, self.img_x_max, self.img_y_max))
      imgUnpadded[0,:,:],xedges,yedges = np.histogram2d(df['img_x'],
                                         df['img_y'],
                                         bins = [self.img_x_max, self.img_y_max])
      imgUnpadded[1,:,:],xedges,yedges = np.histogram2d(df['img_x'],
                                         df['img_y'],
                                         bins = [self.img_x_max, self.img_y_max],
                                         weights = df['u'])
      imgUnpadded[2,:,:],xedges,yedges = np.histogram2d(df['img_x'],
                                         df['img_y'],
                                         bins = [self.img_x_max, self.img_y_max],
                                         weights = df['v'])
      return imgUnpadded
  
  def _img_normlization(self, imgUnpadded, ymax, xmax):
      if 'pad' in self.img_params:
          pad = self.img_params['pad']
      else:
          pad = 50
      img0 = np.pad(imgUnpadded[0,:,:],pad,'constant',constant_values = 0)
      img = np.zeros((3, xmax+2*pad, ymax+2*pad))
      for ic in range(1,3):
          img[ic,:,:] = np.pad(imgUnpadded[ic,:,:],pad,'constant',constant_values = 0)
          img[ic,:,:] = np.nan_to_num(img[ic,:,:]/img0)
          img[ic,:,:] -= img[ic,:,:].min()
          img[ic,:,:] /= img[ic,:,:].max()
      img0 = np.nan_to_num(img0/img0)
      img[0,:,:] = img0
      img = np.transpose(img,(1,2,0))
      return img
  
  def _save_img(self, img, i, day, actual_dep_time):
      if 'start_index' in self.img_params:
          output_fn = '%06d' % (i+self.img_params['start_index']) + '_' + day + '_' + actual_dep_time + '.png'
      else:
          output_fn = '%06d' % (i+1) + '_' + day + '_' + actual_dep_time + '.png'
      output_fp = os.path.join(self.save_base_fp, output_fn)
      plt.axis([0, self.img_x_max, 0, self.img_y_max])
      plt.imsave(output_fp, np.transpose(img,(1,0,2)), origin='lower')
  </code></pre>
  
  <p>The 3 functions would be run one by one. The input of _load_img() is a np.DataFrame which have 4 columns ['imgx', 'img_y', 'u', 'v']</p>