I have multiple csv files. I have to plot the current vs voltage plots in one single graph from the data obtained after cleaning arranging the data frame from multiple csv files.
The code for plotting the single graph is as follows,
import pandas as pd
import tkinter as tk
import matplotlib.ticker as ticker
from tkinter import filedialog
import matplotlib.pyplot as plt
root = tk.Tk()
root.withdraw()
root.call('wm', 'attributes', '.', '-topmost', True)
files = filedialog.askopenfilename(multiple=True)
%gui tk
var = root.tk.splitlist(files)
files = []
fig = plt.figure(figsize=(30, 20))
ax = fig.add_subplot()
ax.grid(True)
#ax.set(xlabel="Voltage", ylabel="Current", title="IV Curve")
ax.set_xlabel("Voltage [V]",fontsize = 20)
ax.set_ylabel("Current [I]",fontsize = 20)
ax.set_title("IV Curve Plot",fontweight ='bold', fontsize = 30)
ax.tick_params(axis='both', which='major', labelsize=20)
plt.ylim (0.1,10) #adjust the voltage limits
plt.xlim (0.1,50) #adjust the current limits
plt.savefig('/home/hebin/Desktop/PV/Mitsui/hotspot/IV.png', dpi=100)
for i,file in enumerate(files,1):
df = pd.read_csv(file, index_col=None, header=0, encoding='ISO-8859–1')
cols_of_lists = ['RawCurrent', 'RawVoltage', 'RawPower', 'CorrectedCurrent', 'CorrectedVoltage', 'CorrectedPower']
# convert these columns from strings to lists
df[cols_of_lists] = df[cols_of_lists].apply(lambda x: x.str.replace('[', '').str.replace(']', '').str.split(','))
# get CorrectedVoltage and CorrectedPower
cv = df[cols_of_lists[3:5]].apply(pd.Series.explode).astype(float).reset_index(drop=True)
# add line to figure
ax.plot('CorrectedVoltage', 'CorrectedCurrent', data=cv, linewidth=2, label =f'IV: {i}')
# print measurement information
print(f'IV: {file}')
voltage = cv["CorrectedVoltage"].values.max()
current = cv["CorrectedCurrent"].values.max()
Power = df["Pmax"].values.max()
print("Voc =", voltage)
print("Isc =", current)
print('Impp =', df['I MPP'].values.max())
print('Vmpp =', df['V MPP'].values.max())
print('Irradiance = W/m²', df['Irradiance W/m²'].values.max())
print('Power=', Power)
print('\n')
plt.legend() # add the legend
plt.show() # show the plot
This is an example csv file - https://1drv.ms/u/s!Au0g20aAwHJyhRcHzAVswst8WD-V?e=C5GSAb Like this, I have to pull, clean and plot multiple IV curve in one single plot.
Kindly help to solve this problem