Last active
February 1, 2020 13:00
-
-
Save selflein/07e6cf7f745595ffba1808c33700950d to your computer and use it in GitHub Desktop.
Save image with same resolution without border etc. using matplotlib #python #matplotlib
This file contains 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
dpi = 80 | |
# What size does the figure need to be in inches to fit the image? | |
figsize = width / float(dpi), height / float(dpi) | |
# Create a figure of the right size with one axes that takes up the full figure | |
fig = plt.figure(figsize=figsize) | |
ax = fig.add_axes([0, 0, 1, 1]) | |
ax.set_aspect('equal', adjustable='box') | |
# Hide spines, ticks, etc. | |
ax.axis('off') | |
# Display the image. | |
ax.imshow(img) | |
# Annotate something etc. | |
# ... | |
fig.savefig('out.png', dpi=dpi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment