Python Save Plot

how to save matplotlib figure to png
In [5]: plt.savefig('books_read.png')
save plot python
from matplotlib import pyplot as plt

plt.savefig('Path/FigureName.png')
save plot in python
plt.savefig('books_read.png')
python save plot
from matplotlib import pyplot as plt

plt.savefig('foo.png')
plt.savefig('foo.pdf')
python code for where to save the figures
#where to save the figures
PROJECT_ROOT_DIR = "."
CHAPTER_ID = "classification"
IMAGES_PATH = os.path.join(PROJECT_ROOT_DIR, "images", CHAPTER_ID)
os.makedirs(IMAGES_PATH, exist_ok = True)

def save_fig(fig_id, tight_layout=True, fig_extension="png", resolution=300):
path = os.path.join(IMAGES_PATH, fig_id + "." + fig_extension)
print("Saving figure", fig_id)
if tight_layout:
plt.tight_layout()
plt.savefig(path, format=fig_extension, dpi=resolution)

 

Leave a Comment