I am fairly inexperienced with python but I have quite a lot of data (csv) that I need to process and plot in figures. My question is when using plt.savefig
how would I reference the figure file name from a file name that I have created previously?
print(f'Output File : {foname_str}')
plt.savefig(str("{foname_str}"), dpi = 1000)
I want to name the file as exactly the same as my previous file that I have created without going to the directory and copy it's name or its path to plt.savefig(.....)
. It seems the above snippet of code names the file as foname_str.png instead of the actual name of the file XX_YY_ZZ.
I believe you tried to do an
f-string
(https://docs.python.org/3/tutorial/inputoutput.html), but you forgot thef
. Try this:If you are running your python file from another directory then it will save in that one.
To get it in the same directory you could do that: