简体   繁体   中英

Python, save a matplotlib figure with output file name and output directory in a variable

In my script, I want to take image name as an argument (argv) and do some image processing then save it an output directory with a filename like inputFileName_output.

# saving figure
UPLOAD_FOLDER = "./Output_Images_test"
outputfile = file.split(".")[0] + "__output.txt"
plt.savefig("%s/%s", dpi=300) %UPLOAD_FOLDER %outputfile

If someone runs into the same problem as me, here's what I did to solve it. I joined the upload folder and outputfile using os.path.join.

# saving figure

outputfile_name = file.split(".")[0] + "__output.png"
output_image_path = os.path.join(UPLOAD_FOLDER, outputfile_name)
plt.savefig(output_image_path, dpi=300)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM