mujoco训练数据绘制

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
######################查看环境所支持的中文字体类型#################
# 本人所用版本,仅支持两种中文字体:AR PL UKai CN、AR PL UMing CN
# from matplotlib.font_manager import FontManager
# import subprocess
#
# mpl_fonts = set(f.name for f in FontManager().ttflist)
#
# print('all font list get from matplotlib.font_manager:')
# for f in sorted(mpl_fonts):
#     print('\t' + f)
# plt.rc("font",family='LiSu') # 修改字体方式1
#################################################################
####################从上面打印出的中文字体中选择一个###################
plt.rcParams['font.sans-serif']=['STKaiti'] # 修改字体方式2:显示中文
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号

# 读取CSV文件,一下读取三个文件,进行绘图,对应三条曲线
data1 = pd.read_csv('前向.csv')
data2 = pd.read_csv('侧向.csv')
data3 = pd.read_csv('对角线.csv')
# 获取数据列
steps1 = data1['Step']
values1 = data1['Value']
steps2 = data2['Step']
values2 = data2['Value']
steps3 = data3['Step']
values3 = data3['Value']

# 平滑处理
window_size = 10
smoothed_values1 = np.convolve(values1, np.ones(window_size)/window_size, mode='valid')
smoothed_steps1 = steps1[window_size-1:]
smoothed_values2 = np.convolve(values2, np.ones(window_size)/window_size, mode='valid')
smoothed_steps2 = steps2[window_size-1:]
smoothed_values3 = np.convolve(values3, np.ones(window_size)/window_size, mode='valid')
smoothed_steps3 = steps3[window_size-1:]

# 绘制图表
plt.plot(smoothed_steps1, smoothed_values1, color='red', label='v=[0.8,0.0]', linewidth=1.5)
plt.plot(smoothed_steps2, smoothed_values2, color='blue', label='v=[0.0,0.4]', linewidth=1.5, linestyle='--')
plt.plot(smoothed_steps3, smoothed_values3, color='green', label='v=[-0.5,-0.3]', linewidth=1.5, linestyle=':')

# 修改折线颜色代码
# plt.plot(smoothed_steps, smoothed_values, color='red')

# 修改x轴和y轴刻度代码
plt.xlim(0,None)

# 添加x轴和y轴标签
plt.xlabel(u'采集次数', fontsize=15)
plt.ylabel(u'综合奖励值', fontsize=15)

plt.xticks(np.arange(0, max(smoothed_steps1)+1, 5000000))
# plt.yticks(np.arange(0, max(smoothed_values)+1, 0.05))

# 设置曲线标注位置
plt.legend(loc="lower right")
ax = plt.subplot()
ax.set_xticks([0, 5000000, 10000000, 15000000, 20000000, 25000000, 30000000, 35000000, 40000000])
ax.set_xticklabels(('0M','5M','10M', '15M', '20M', '25M', '30M', '35M', '40M'))   # 不显示‘five’

plt.show()




你可能感兴趣的:(强化学习,python,开发语言)