import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
if __name__ == '__main__':
mpl.rcParams['font.family'] = 'STSong'
mpl.rcParams['axes.unicode_minus'] = False
# 选择的分别是-注视时间,-首次注视时间,-注视次数
selected = ['IA_DWELL_TIME', 'IA_FIRST_FIXATION_DURATION', 'IA_FIXATION_COUNT']
selected_chi = ['平均注视时间','首次注视时间','注视次数']
for count in range(1,2):
selected_img = 'Y' + str(count) + ".JPG"
all_data = pd.read_excel('./zlj5.xlsx')
# print(all_data)
all_mean = []
all_var = []
all_SelectedImg = all_data[all_data['image'] == selected_img]
all1Img = all_SelectedImg[all_SelectedImg['IA_LABEL'] == 1]
all2Img = all_SelectedImg[all_SelectedImg['IA_LABEL'] == 2]
all3Img = all_SelectedImg[all_SelectedImg['IA_LABEL'] == 3]
all4Img = all_SelectedImg[all_SelectedImg['IA_LABEL'] == 4]
# , all3Img, all4Img
data = [all1Img,all2Img,all3Img,all4Img]
for i in range(len(data)):
for index, name in enumerate(selected):
if name != "IA_FIRST_FIXATION_DURATION":
tmp = np.array(data[i][name].tolist())
else:
tmp = data[i][data[i][name] != '.']
tmp = np.array(tmp[name].tolist())
all_mean.append(tmp.mean() / tmp.max())
plotData = np.array([all_mean[i : i + 3] for i in range(0, len(all_mean),3)])
# print(plotData)
# print(plotData[:,0])
# print(mpl.rcParamsDefault)
width = 0.2 # the width of bar
ind = np.arange(plotData.shape[0]) # the x locations for the groups
fig, ax = plt.subplots()
ax.bar(ind - 3 * width / 2, plotData[:,0], width, color='#D3D3D3', label='平均注视时间')
ax.bar(ind - 1 * width / 2, plotData[:,1], width, color='#FFB6C1', label='首次注视时间')
ax.bar(ind + 1 * width / 2, plotData[:,2], width, color='#12B4E5', label='注视次数')
ax.set_ylabel('平均值与最大值比值(%)')
ax.set_title(selected_img,pad=20)
print(ind-1 * width / 2)
print(ind)
plt.xticks(ind - 1 * width / 2, ('分组1', '分组2','分组3','分组4'))
plt.legend(loc=2, bbox_to_anchor=(1,1),borderaxespad = 0.)
plt.subplots_adjust(right=0.78)
plt.savefig("C:/Users/珍惜/Desktop/PythonMachineLearning/20201109/zlj3/" +'Y' + str(count) + '/'+selected_img+'.jpg')
plt.show()
Python中为朋友画图操作
最新推荐文章于 2021-10-15 11:08:45 发布