I am trying to write a script that will analyze the performance of a machine based on operation time (time vs power). this means more and more csv files will be generated and will be added to the plot.
all the csv's are in the same folder. my code is:
import pandas as pd
import os
import matplotlib.pyplot as plt
import numpy
from datetime import datetime
from pathlib import Path
import pandas as pd
dateparse = lambda x: datetime.strptime(x, '%d-%b-%Y %I:%M:%S:%f %p')
folder = r"path adrress"
files = Path(folder).rglob('*.csv')
result_path = r"path adrress"
fig = plt.figure(figsize=(60, 20))
plt.grid(True)
plt.ylim(bottom=43.5, top=44.5)
plt.xlabel("Time (s)", size=50)
plt.ylabel("Power (dBm)", size=50)
color = ['black', 'red', 'green', 'orange', 'blue', 'purple']
label = ['504', '505', '506']
for i, file in enumerate(files):
df_files = (pd.read_csv(file, skiprows=7, parse_dates=['Time Stamp'], date_parser=dateparse) for file in files)
df = pd.concat(df_files)
x = df['Time Stamp']
y = df[' Power (dBm)'].to_numpy()
plt.scatter(x, y, color=color[i], label=label[i], linewidth=4)
plt.legend(loc=3, prop={'size': 30}, markerscale=5)
plt.xticks(color='k', size=50)
plt.yticks(color='k', size=50)
os.makedirs(result_path, exist_ok=True)
imageFileName = os.path.join(result_path, 'plot.png')
if os.path.isfile(imageFileName):
os.remove(imageFileName)
plt.savefig(imageFileName)
plt.close(fig)
the code creates a single plot in a single color with a single instance in the legend instead of 3 (currently 3 files in the folder).
How can I reflect the different files in the figure ?