Last active
May 22, 2021 19:05
-
-
Save hbshrestha/87f449abdf448c6952da5e9b2009b271 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Number of frames equivalent to number of rows | |
numOfFrames=df.shape[0] | |
top_clubs=["Atletico Madrid","Real Madrid","FC Barcelona"] | |
x_init = np.array([1]) | |
initial_data = [] | |
for club in top_clubs: | |
y_axis = np.array(df.loc[0, club]) | |
initial_data.append(go.Scatter(x =x_init, y = y_axis,mode = "lines",name = club)) | |
# Frames | |
frames = [] #Initialize as an empty list | |
for f in range(1,numOfFrames): | |
x_axis = np.arange(1,f+1) | |
current_data = [] | |
for club in top_clubs: | |
current_club = df[club] | |
y_axis = np.array(df.loc[1:f, club]) | |
current_data.append(go.Scatter(x = x_axis, y = y_axis,mode = "lines", name = club)) | |
current_frame = go.Frame(data = current_data) | |
frames.append(current_frame) | |
figure=go.Figure(data=initial_data, | |
layout={"title":"La Liga 2020/21 Race", | |
"title_x":0.5, #Set title alignment to centre | |
"xaxis":{"range":[0,39], "visible":True, "title":"Match Day"}, | |
"yaxis":{"range":[0,100],"visible":True, "title":"Total Points"}, | |
"updatemenus":[{"type":"buttons","buttons":[{"method":"animate","label":"play", "args":[None]}]}], | |
"font":{"size":18} | |
}, | |
frames=frames) | |
figure.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment