【发布时间】:2020-09-07 10:18:35
【问题描述】:
我有以下代码,我希望用户输入来构建条形图。然而,直到用户退出函数,情节才真正显现出来?
def get_plot():
while True:
again = input("Do you want to visualise a player's pb scores?")
if again == 'yes':
while True:
player_name = input("What player do you want to visualise PB scores for the 19/20 season?").title()
if player_name in historics.values:
print("Player is present within the underlying data")
break
else:
print("Player does not exist within the underlying data")
is_player = historics['Player Name'] == player_name
new_table = historics[is_player]
#now we will use this data to produce a bar chart for this player, showing their pb scores over the 19/20 season
def get_graph():
plt.bar(new_table.Date,new_table['Matchday Score'],color="g")
plt.title("%s's PB scores for 19/20 season" % player_name)
plt.xlabel("Date")
plt.ylabel("Matchday Score")
if 'Forward' in new_table['FI Player Current Position'].values:
plt.axhline(y=255.56, color='gold', linestyle='-')
plt.axhline(y=239.94, color='slategrey', linestyle='-')
plt.axhline(y=173.52, color='saddlebrown', linestyle='-')
elif 'Midfielder' in new_table['FI Player Current Position'].values:
plt.axhline(y=262.44, color='gold', linestyle='-')
plt.axhline(y=263.35, color='slategrey', linestyle='-')
plt.axhline(y=205.66, color='saddlebrown', linestyle='-')
else:
plt.axhline(y=232.62, color='gold', linestyle='-')
plt.axhline(y=227.43, color='slategrey', linestyle='-')
plt.axhline(y=182.36, color='saddlebrown', linestyle='-')
plt.rcParams["figure.figsize"]=10,5
plt.show()
get_graph()
if again == 'no':
break
else:
print("Please provide a valid value")
get_plot()
所以在输入“no”后,显示最后提供的 player_name 值的图。但是,我希望在输入 player_name 值时创建(并显示)绘图,并在提供的每个后续值时刷新绘图?
我哪里错了?
谢谢。
编辑:数据示例(historics.head()):
Date Player Name Team Name Opposition \
0 2020-08-23 Kingsley Coman Bayern München Paris Saint Germain
1 2020-08-23 Joshua Kimmich Bayern München Paris Saint Germain
2 2020-08-23 Thiago Alcántara Bayern München Paris Saint Germain
3 2020-08-23 Manuel Neuer Bayern München Paris Saint Germain
4 2020-08-23 David Alaba Bayern München Paris Saint Germain
Home or Away? Competition Starting Lineup? Formation \
0 Away Champions League Lineup 4-2-3-1
1 Away Champions League Lineup 4-2-3-1
2 Away Champions League Lineup 4-2-3-1
3 Away Champions League Lineup 4-2-3-1
4 Away Champions League Lineup 4-2-3-1
Matchday Dividends FI Game Position ... Interceptions Blocks Clearances \
0 0.18 Forward ... 0.0 0.0 0.0
1 0.10 Midfielder ... 1.0 1.0 1.0
2 0.00 Midfielder ... 2.0 0.0 0.0
3 0.00 Goalkeeper ... 0.0 0.0 0.0
4 0.00 Defender ... 1.0 0.0 2.0
Offsides Fouls Committed Yellow Cards Red Card (Two Yellows) \
0 0.0 0.0 0.0 0.0
1 0.0 1.0 0.0 0.0
2 NaN 4.0 0.0 0.0
3 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0
Straight Red Cards Goals Conceded (GKs) \
0 0.0 0.0
1 0.0 0.0
2 0.0 0.0
3 0.0 0.0
4 0.0 0.0
Different Game Position to Current FI Position?
0 1
1 1
2 0
3 0
4 0
【问题讨论】:
-
您能发布您的数据吗?
-
在我的初始帖子中添加了一些示例数据
标签: python python-3.x matplotlib jupyter-notebook