Skip to content

Instantly share code, notes, and snippets.

@338rajesh
Created April 1, 2022 03:47
Show Gist options
  • Save 338rajesh/deb3098e2c1d0e4deee788c7e92b6206 to your computer and use it in GitHub Desktop.
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.
# 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