问题描述
我有一个DataFrame,其中包含有关多个事件的信息。使用每个DataFrame中的信息,我开发了代码,在彼此列出顶部的空间图上放置了多个图。目前,我一次只能执行一个实例,而数据框中的事件列有132个实例。基本上,我想创建一个循环来重新创建此过程(对于事件1-132),该过程将保存每个图并将其标题设置为当前事件编号。
current_events = [i for i in event_data['number']]
current_tracking = [i for i in track_data['number']]
#Subsetting relevant dataframes
current_tracking = current_tracking.reset_index().sort_values(by=['Id','Time','index'],ascending = [True,True,True]).drop(['index'],axis=1)
#Sorting the tracking data for accessibility
start_loc = current_tracking[current_tracking['type'] == 'start']
ID_tracks = current_tracking[current_tracking['player_role'].isin(['Id_1','Id_2','Id_3'])]
#Location of the end of play event for reference
end_loc = current_events[current_events['shorthand'] == 'END OF EVENT']
#Starting Location of every ID for Scatterplot
x = start_loc['xCoord']
y = start_loc['yCoord']
color = start_loc['group']
#Tracking @R_963_4045@ion to plot ID routes
x1 = Id_tracks['xCoord']
y1 = Id_tracks['yCoord']
color2 = Id_tracks['Id']
x2 = end_loc['xCoord']
y2 = end_loc['yCoord']
fig_dims = (10,8)
fig,ax = plt.subplots(figsize=fig_dims)
ax.set_title('Event Number: {}'.format(i))
sns.scatterplot(x,y,hue = color,legend= False)
label_point(x,start_loc.Id,ax) #A function I defined prevIoUsly to label each scatterplot point
sns.lineplot(x1,y1,color2,legend=False,ci = None)
plt.plot(x2,y2,color='red',marker='o')
plt.savefig('Event {}.png'.format(i))
我尝试了几次,并在语法上遇到了许多错误。我猜我对循环的理解是错误的,有什么想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)