Python中为朋友画图操作

20 篇文章 0 订阅
3 篇文章 0 订阅
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()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值