#自定义绘图函数,传入组合柱状图的均值(及标准差)二维列表、分组名称列表、图例名称列表
def plotHis(twoDMeanList=[[1,2],[3,4],[5,6]],twoDStdList='',groupNameList=['group1','group2'],legendList=['A','B','C'],xlabel='X',ylabel='Y',figWidth=10,figHeight=6):
width=1
groupNum=len(twoDMeanList[0])
barNum=len(twoDMeanList)
x=np.arange(0,groupNum*(barNum+2),barNum+2)
fig,ax=plt.subplots(1,1,figsize=(figWidth,figHeight))
locList=list(range(-(barNum//2),barNum//2+1))
for i in locList:
if twoDStdList!='':
ax.bar(x+i*width,twoDMeanList[locList.index(i)],width,yerr=twoDStdList[locList.index(i)],label=legendList[locList.index(i)])
else:
ax.bar(x+i*width,twoDMeanList[locList.index(i)],width,label=legendList[locList.index(i)])
ax.set_xticks(x)
ax.set_xticklabels(groupNameList)
ax.legend()
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
|