Seems like you might just have the wrong command on plt.save
, try plt.savefig
instead?
EDIT:
Might be a few things that are going wrong here, but assuming "lisst" is a list of column names and "m" is a pandas dataframe with "Time" as a datetime column (not index!), this might work:
# Set path explicitly as a variable with escapes (assuming Windows)
path = "C:\\Users\\parsa\\Desktop\\kholase\\"
# Check if path to the path exists and if not, create it
import os
if not os.path.exists(path):
os.makedirs(path)
# Define the function
def curve(lisst , m):
for i in lisst:
if i in m.columns:
# Create figure and axis separately
fig, ax = plt.subplots()
# Set title
plt.title(i) # `fig.suptitle(i)` works too
# Plot on the axis
ax.plot(m.Time , m[i])
# Concatenate path with f-string filename and save figure
fig.savefig(path + f"image{i}.png", format="png")
# Call the function to produce the plots
curve(lisst, m)
Instead of fig.savefig
just plt.savefig
should work the same here.