title: Specifying and saving a figure with exact size in pixels
body: <p>Say I have an image of size 3841 x 7195 pixels. I would like to save the contents of the figure to disk, resulting in an image of the <strong>exact size</strong> I specify in pixels.</p>
  
  <p>No axis, no titles. Just the image. I don't personally care about DPIs, as I only want to specify the size the image takes in the screen in disk <strong>in pixels</strong>.</p>
  
  <p>I have read <a href="https://stackoverflow.com/search?q=figure%20size%20matplotlib">other</a> <a href="https://stackoverflow.com/questions/8775622/exact-figure-size-in-matplotlib-with-title-axis-labels">threads</a>, and they all seem to do conversions to inches and then specify the dimensions of the figure in inches and adjust dpi's in some way. I would like to avoid dealing with the potential loss of accuracy that could result from pixel-to-inches conversions.</p>
  
  <p>I have tried with:</p>
  
  <pre><code>w = 7195
  h = 3841
  fig = plt.figure(frameon=False)
  fig.set_size_inches(w,h)
  ax = plt.Axes(fig, [0., 0., 1., 1.])
  ax.set_axis_off()
  fig.add_axes(ax)
  ax.imshow(im_np, aspect='normal')
  fig.savefig(some_path, dpi=1)
  </code></pre>
  
  <p>with no luck (Python complains that width and height must each be below 32768 (?))</p>
  
  <p>From everything I have seen, <code>matplotlib</code> requires the figure size to be specified in <code>inches</code> and <code>dpi</code>, but I am only interested in <strong>the pixels</strong> the figure takes in disk. How can I do this?</p>
  
  <p>To clarify: I am looking for a way to do this with <code>matplotlib</code>, and not with other image-saving libraries.</p>