Files
easy-rl/codes/common/plot.py
johnjim0816 8028f7145e update
2021-05-03 23:00:01 +08:00

44 lines
1.3 KiB
Python

#!/usr/bin/env python
# coding=utf-8
'''
Author: John
Email: johnjim0816@gmail.com
Date: 2020-10-07 20:57:11
LastEditor: John
LastEditTime: 2021-04-29 15:41:48
Discription:
Environment:
'''
import matplotlib.pyplot as plt
import seaborn as sns
def plot_rewards(rewards,ma_rewards,tag="train",env='CartPole-v0',algo = "DQN",save=True,path='./'):
sns.set()
plt.title("average learning curve of {} for {}".format(algo,env))
plt.xlabel('epsiodes')
plt.plot(rewards,label='rewards')
plt.plot(ma_rewards,label='ma rewards')
plt.legend()
if save:
plt.savefig(path+"{}_rewards_curve".format(tag))
plt.show()
# def plot_rewards(dic,tag="train",env='CartPole-v0',algo = "DQN",save=True,path='./'):
# sns.set()
# plt.title("average learning curve of {} for {}".format(algo,env))
# plt.xlabel('epsiodes')
# for key, value in dic.items():
# plt.plot(value,label=key)
# plt.legend()
# if save:
# plt.savefig(path+algo+"_rewards_curve_{}".format(tag))
# plt.show()
def plot_losses(losses,algo = "DQN",save=True,path='./'):
sns.set()
plt.title("loss curve of {}".format(algo))
plt.xlabel('epsiodes')
plt.plot(losses,label='rewards')
plt.legend()
if save:
plt.savefig(path+"losses_curve")
plt.show()