1# Basic syntax:
2plt.savefig("/path/to/output/directory/figure.png")
3
4# Example usage:
5import matplotlib.pyplot as plt
6plt.figure()
7plt.plot(range(5))
8plt.savefig("~/Documents/figure.png", dpi=300)
1#where to save the figures
2PROJECT_ROOT_DIR = "."
3CHAPTER_ID = "classification"
4IMAGES_PATH = os.path.join(PROJECT_ROOT_DIR, "images", CHAPTER_ID)
5os.makedirs(IMAGES_PATH, exist_ok = True)
6
7def save_fig(fig_id, tight_layout=True, fig_extension="png", resolution=300):
8 path = os.path.join(IMAGES_PATH, fig_id + "." + fig_extension)
9 print("Saving figure", fig_id)
10 if tight_layout:
11 plt.tight_layout()
12 plt.savefig(path, format=fig_extension, dpi=resolution)
1import matplotlib.pyplot as plt
2plt.figure()
3plt.plot([1,2,3],[1,2,3])
4plt.savefig("out.png")