Created
November 14, 2021 10:10
-
-
Save renyuanL/00b6ea11ac42ddacc06a8ea356f9008d 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
import numpy as np | |
import matplotlib.pyplot as plt | |
#color= ['red', 'green', 'blue', 'magenta'] | |
fig= plt.figure() | |
plt.xticks(rotation= 45, | |
ha= "right", | |
rotation_mode="anchor") #rotate the x-axis values | |
plt.subplots_adjust(bottom = 0.2, | |
top = 0.9, | |
left= .2, | |
right=.9) #ensuring the dates (on the x-axis) fit in the screen | |
plt.ylabel('$USD') | |
plt.xlabel('Date') | |
plt.title('Personal Value of Stock in USD$') | |
def buildmebarchart(i= int): | |
p= plt.plot(Y['Personal Value'][:i].index, | |
Y['Personal Value'][:i].values) #note it only returns the dataset, up to the point i | |
p[0].set_color('green') #set the colour of each curve | |
plt.legend(['Personal Value']) | |
plt.grid() | |
import matplotlib.animation as ani | |
animator= ani.FuncAnimation(fig, | |
buildmebarchart, | |
interval= 50, | |
repeat= True, | |
#cache_frame_data= False | |
) | |
#plt.show() | |
#animator.save('__ryPersonalValue.mp4', fps= 15) | |
animator.save('__ryPersonalValue.gif') | |
#plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment