Created
April 1, 2022 03:47
-
-
Save 338rajesh/deb3098e2c1d0e4deee788c7e92b6206 to your computer and use it in GitHub Desktop.
Code for generating matplotlib based plots, where plot is saved at specified pixels in width and height direction and without axes, ticks, whitespace.
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
# source: this stackoverflow thread : https://stackoverflow.com/questions/8218608/scipy-savefig-without-frames-axes-only-content/8218887#8218887 | |
# | |
width_pixels = 5 | |
height_pixels = 5 | |
using matplotlib.pyplot as plt | |
fig = plt.figure(frameon=False) | |
fig.set_size_inches(width_pixels, height_pixels) | |
# | |
ax = plt.Axes(fig, [0., 0., 1., 1.]) | |
ax.set_axis_off() | |
fig.add_axes(ax) | |
# | |
# some code for plotting the figure | |
plt.savefig(image_path, dpi=1) | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment