import numpy as npimport pandas as pd #import networkx as nximport matplotlib.pyplot as pltimport randomfrom collections import *import csv import pickle import os
二、修改当前文件工作路径os.getcwd() # 获得当前工作路径cd "C:\Users\Administrator\Desktop\潘\GDDPG\model_plot\L" # 修改工作路径### 获得当前文件路径下的文件lpath="C:\Users\Administrator\Desktop\潘\GDDPG\model_plot\L"for root, dirs, files in os.walk(lpath): print(files)
三、画loss的两个model的morning段的图## 单独画GRLPA_flow_morning_loss图# 先改工作位置fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)l_f='loss1000GRLPA29morningflow_weekday.pkl'#l_u='loss1000GRLPA29morningunweighted_weekday.pkl'loss = pickle.load(open(l_f,"rb"))loss = np.asarray(loss)loss = loss[::2][:100]x = range(len(loss))label = "morning"ax1.plot(x,loss,color="orange",label=label)ax1.legend()#plt.title("GRLPA model under flow-matrix in the morning") plt.savefig("GRLPA_flow_morning.png")
第二个
## 单独画GRLPA_unweighted_morning_loss图# 先改工作位置fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)#l_f='loss1000GRLPA29morningflow_weekday.pkl'l_u='loss1000GRLPA29morningunweighted_weekday.pkl'loss = pickle.load(open(l_u,"rb"))loss = np.asarray(loss)loss = loss[::2][:100]x = range(len(loss))label = "morning"ax1.plot(x,loss,color="orange",label=label)ax1.legend()#plt.title("GRLPA model under flow-matrix in the morning") plt.savefig("GRLPA_unweighted_morning.png")
四、画loss的3个model的三个时间段的图fig1, ax1 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "GRLPA" in f: if "flow" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax1.plot(x,loss,label=label) ax1.legend()plt.title("GRLPA model under flow-matrix") plt.savefig("GRLPA_flow.png")fig2, ax2 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "GRLPA" in f: if "unweighted" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax2.plot(x,loss,label=label) ax2.legend() plt.title("GRLPA model under unweighted-matrix") plt.savefig("GRLPA_unweighted.png")fig3, ax3 = plt.subplots(figsize=(8, 5), dpi=80)for f in files: if "DDPG" in f: loss = pickle.load(open(f,"rb")) loss = np.asarray(loss) loss = loss[::2] x = range(len(loss)) label = Judge_Label(f) if label is not None: ax3.plot(x,loss,label=label) ax3.legend() plt.title("DDPG model under unweighted-matrix") plt.savefig("DDPG_loss.png")
附录:调用函数## 获取L文件夹下的所有为.pkl的文件def juduge_labdel(f): if "DDPG" in f: if "morning" in f: label="DDPG_morning" elif "noon" in f : label="DDPG_noon" elif "evening" in f or "eveining" in f: label="DDPG_evening" else : label= None if "GRLPA" in f: if "flow" in f: if "morning" in f: label="GRLPA_morning_flow" elif "noon" in f : label="GRLPA_noon_flow" elif "evening" in f or "eveining" in f: label="GRLPA_evening_flow" else: label= None else: if "morning" in f: label="GRLPA_morning_unweighted" elif "noon" in f : label="GRLPA_noon_unweighted" elif "evening" in f or "eveining" in f: label="GRLPA_evening_unweighted" else: label= None return labeldef Judge_Label(f): if "morning" in f: label="morning" elif "noon" in f : label="noon" elif "evening" in f or "eveining" in f: label="evening" else: label= None return label