python 绘制直方图代码

import matplotlib.pyplot as plt
import numpy as np

x=np.arange(3)
#数据集
CQL=[11.17,2368.12,3347.40]
PER200=[84.62,2546.82,3470.67]
PER1000=[15.61,1811.55,3618.98]


# Mean:11.176983833333333, 84.62270609666666, 15.615813731166664,
# 2368.1278483333335, 2546.8221843333336, 1811.5576731666667,
# 3347.401896166667, 3470.671753, 3618.9807536666667

# Std:10.184114435131907, 63.006250938288964, 6.361710626865148,
# 637.8259946466884, 144.8657849717389, 1089.9137299651895,
# 335.3746672111984, 8.67876906354258, 1.2835293595462538

 

#误差列表
std_err1=[10,637,335]
std_err2=[63,144,8]
std_err3=[6,1089,1]
tick_label=['random','medium','medium-expert']

error_params1=dict(elinewidth=3,ecolor='crimson',capsize=4)#设置误差标记参数
error_params2=dict(elinewidth=3,ecolor='blueviolet',capsize=4)#设置误差标记参数
error_params3=dict(elinewidth=3,ecolor='crimson',capsize=4)#设置误差标记参数

#设置柱状图宽度
bar_width=0.25
myfig = plt.gcf()

#绘制柱状图,设置误差标记以及柱状图标签
plt.bar(x,CQL,bar_width,color=['yellow','yellow','yellow'],yerr=std_err1,error_kw=error_params1,label='CQL')
plt.bar(x+bar_width,PER200,bar_width,color=['blue','blue','blue'],yerr=std_err2,error_kw=error_params2,label='CQL_PER_200K')
plt.bar(x+bar_width+bar_width,PER1000,bar_width,color=['green','green','green'],yerr=std_err3,error_kw=error_params3,label='CQL_PER_1000K')

plt.xticks(x+bar_width,tick_label)#设置x轴的标签
#设置网格
plt.grid(True,axis='y',ls=':',color='r',alpha=0.3)
#显示图例
plt.legend()

plt.xlabel("hopper",fontsize="12")
plt.ylabel("episode return",fontsize="12")

#显示图形
plt.show()

myfig.savefig("offline_hist_main_experiment_hopper.png",dpi=300, bbox_inches = 'tight')

 

 

posted @ 2022-10-20 14:53  呦呦南山  阅读(366)  评论(0编辑  收藏  举报