# Suppose variable `reward_sum` is a list containing all the reward summary scalars defplot_with_variance(reward_mean, reward_std, color='yellow', savefig_dir=None): """plot_with_variance reward_mean: typr list, containing all the means of reward summmary scalars collected during training reward_std: type list, containing all variance savefig_dir: if not None, this must be a str representing the directory to save the figure """ half_reward_std = reward_std / 2.0 lower = [x - y for x, y in zip(reward_mean, half_reward_std)] upper = [x + y for x, y in zip(reward_mean, half_reward_std)] plt.figure() xaxis = list(range(len(lower))) plt.plot(xaxis, reward_mean, color=color) plt.fill_between(xaxis, lower, upper, color=color, alpha=0.2) plt.grid() plt.xlabel('Episode') plt.ylabel('Average reward') plt.title('The convergence of rewards') if savefig_dir isnotNoneand type(savefig_dir) is str: plt.savefig(savefig_dir, format='svg') plt.show()