3

Im plotting some lines over a bitmap image in matplotlib. How do I make the image output by savefig the same size as the original image? I have the following code, but it still gives me a white border on the left and bottom, and the image is more than 100x100 pixels.

You can %paste the code below to see what I mean:

import matplotlib.pyplot as plt
import numpy as np

plt.figure()
plt.imshow(np.eye(100))
plt.plot([1, 10, 20, 30, 40], [5, 100, 5, 100, 3], lw=3)
plt.ylim(0,100)
plt.xlim(0,100)
plt.axis('off')
plt.savefig('test.png', bbox_inches='tight', pad_inches=0)
noio
  • 5,744
  • 7
  • 44
  • 61
  • Have a look at this: http://stackoverflow.com/questions/16057869/setting-the-size-of-the-plotting-canvas-in-matplotlib/16061699#16061699 – Rutger Kassies Jun 06 '13 at 12:16
  • Ah, yes, I was afraid I'd have to mess with DPI already :( – noio Jun 06 '13 at 13:07
  • In case you don't care about the re-sampling and exact pixel dimensions of the resulting image, see **[my answer here](https://stackoverflow.com/a/32174837/897968)** for a slightly simpler solution. – FriendFX Aug 24 '15 at 05:26

0 Answers0