Skip to content

Commit

Permalink
feat: add graph/parse.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-TW committed Oct 13, 2024
1 parent 61b2f94 commit bf955f0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/graph/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pandas as pd
import matplotlib.pyplot as plt

def parse_and_plot(csv_file):
# 讀取 CSV 檔案
try:
df = pd.read_csv(csv_file, header=None)
# 提取迭代次數和價值數據
iteration_data = df.iloc[::2, 0].str.split(expand=True)
iteration_data.columns = ['Iteration', 'Value', 'Weight', 'Length']

# 確保數據為數值類型
iteration_data['Iteration'] = pd.to_numeric(iteration_data['Iteration'])
iteration_data['Value'] = pd.to_numeric(iteration_data['Value'])

# 繪製圖表
plt.figure(figsize=(10, 6))
plt.plot(iteration_data['Iteration'], iteration_data['Value'], marker='o', linestyle='-', color='b')

# 加入標籤和標題
plt.xlabel('Iteration')
plt.ylabel('Value')
plt.title('Iteration vs Value')

# 顯示圖表
plt.grid(True)
plt.show()

except Exception as e:
print(f"解析 CSV 文件時發生錯誤: {e}")

if __name__ == "__main__":
csv_file = "output.csv"
parse_and_plot(csv_file)

0 comments on commit bf955f0

Please sign in to comment.