python计算平均值画折线图_从折线图绘制matplotlib中的平均值?

博主是一名初学者,正在尝试用Python进行数据分析。他们想要在折线图上显示数据集的平均值,图中表示了多个主题在不同天数的准确性。通过调整代码,他们成功地插入了平均值线,显示了每个主题的平均准确性。
摘要由CSDN通过智能技术生成

I'm fairly new to the coding realm and have been trying to familiarize myself with code for data analysis. I'm trying to figure out how to insert an average of the dataset in this line graph. It contains data from multiple subjects across multiple days, and I'm curious to know if there's any way that I can take an "average" of the data, or the lines, and insert that into this code so that it's displayed on the graph. I've tried searching stack overflow and the matplotlib.org but have fallen short. Any help on this would be appreciated!

**为进一步说明:共有9个主题,每个主题的准确度范围从〜50%-100%。数据是在excel中编译的,该行具有“天”(1-22)和“主题”行(在给定的日期具有相应的准确度,例如,第1天为50%,第2天为65%,依此类推)。

这是我的代码:

importpandasaspdimportmatplotlib.pyplotaspltimportnumpyasnp

df=pd.read_excel('data.xlsx')plt.figure(figsize=(10,7))Day=df['Day']Accuracy=df[['Subject 1','Subject 2','Subject 3','Subject 4','Subject 5','Subject 6','Subject 7','Subject 8','Subject 9']]plt.plot(Day,Accuracy,alpha=0.3)plt.axis([1,22,0.55,1])plt.axhline(y=0.8,color='black',linestyle='--',alpha=0.3)plt.xlabel('Day')plt.ylabel('Accuracy')plt.title("Days to Acquisition by Subject")ax=plt.subplot()ax.set_xticks(Day)plt.show()

这就是我得到的:结果图

解决方案

importpandasaspdimportmatplotlib.pyplotaspltimportnumpyasnp

df=pd.read_excel('data.xlsx')plt.figure(figsize=(10,7))Day=df['Day']Accuracy=df[['Subject 1','Subject 2','Subject 3','Subject 4','Subject 5','Subject 6','Subject 7','Subject 8','Subject 9']]Accuracy_mean=df[['Subject 1','Subject 2','Subject 3','Subject 4','Subject 5','Subject 6','Subject 7','Subject 8','Subject 9']].mean(axis=1)plt.plot(Day,Accuracy,alpha=0.3)plt.plot(Day,Accuracy_mean)plt.axis([1,22,0.55,1])plt.axhline(y=0.8,color='black',linestyle='--',alpha=0.3)plt.xlabel('Day')plt.ylabel('Average Accuracy')plt.title("Days to Acquisition by Subject")ax=plt.subplot()ax.set_xticks(Day)plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值