Created
July 18, 2019 11:17
-
-
Save ducha-aiki/f8d55d6269ca5f9485bb6e8e9df498df to your computer and use it in GitHub Desktop.
Save matplotlib no margins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%matplotlib inline | |
import matplotlib | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
import numpy as np | |
from PIL import Image | |
fname = '../../test-graf/img1.png' | |
img = Image.open(fname).convert('RGB') | |
img = np.array(img) | |
fig, ax = plt.subplots(1,1,figsize=(12,12),frameon=False) | |
fig.subplots_adjust(hspace = 0, wspace = 0) | |
ax.imshow(img), | |
ax.plot(100+np.arange(100), 100+np.arange(100), linewidth=10) | |
ax.grid('off') | |
ax.xaxis.set_major_locator(plt.NullLocator()) | |
ax.yaxis.set_major_locator(plt.NullLocator()) | |
fig.savefig('graf.pdf', bbox_inches = 'tight', pad_inches = 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment