Skip to content

Instantly share code, notes, and snippets.

@ducha-aiki
Created July 18, 2019 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ducha-aiki/f8d55d6269ca5f9485bb6e8e9df498df to your computer and use it in GitHub Desktop.
Save ducha-aiki/f8d55d6269ca5f9485bb6e8e9df498df to your computer and use it in GitHub Desktop.
Save matplotlib no margins
%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