Skip to content

Instantly share code, notes, and snippets.

@zhou13
Last active May 10, 2023 08:34
Show Gist options
  • Select an option

  • Save zhou13/b4ee8e815aee83e88df5b865896aaf5a to your computer and use it in GitHub Desktop.

Select an option

Save zhou13/b4ee8e815aee83e88df5b865896aaf5a to your computer and use it in GitHub Desktop.
matplotlib.pyplot.imshow without margin
plt.gca().set_axis_off()
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.savefig(f"filename.png", transparent=True, bbox_inches="tight", pad_inches=0)
plt.cla()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment