Last active
February 1, 2021 19:55
-
-
Save MauricioLetelier/e4a25fd2d6df819d69f36e9c53f8902e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 matplotlib.pyplot as plt | |
from datetime import timedelta | |
import seaborn as sns | |
from celluloid import Camera | |
camera = Camera(plt.figure(figsize=(17, 9))) | |
sns.set() | |
df1_train["type"] = "lightcoral" | |
df1_test["type"] = "mediumblue" | |
new = pd.concat([df1_train, df1_test]) | |
new["threshold"] = df1_train["distance"].nlargest(25).sum() / 25 * 3 | |
new = new[(new.index > "2021-01-10") & (new.index <= "2021-01-16")] | |
for idx, i in enumerate(new.index): | |
if idx % 1 == 0: | |
# print(len(new[new.index<i])) | |
plt.title("GME") | |
plt.ylabel("Centroid Distance") | |
plt.scatter( | |
new[new.index < i].index, | |
new[new.index < i]["distance"], | |
c=new[new.index < i]["type"], | |
) | |
plt.scatter( | |
new[(new.index < i) & (new["distance"] > new["threshold"])].index, | |
new[(new.index < i) & (new["distance"] > new["threshold"])]["distance"], | |
c=new[(new.index < i) & (new["distance"] > new["threshold"])]["type"], | |
marker="D", | |
s=100, | |
) | |
plt.xlim([new.index.min() - timedelta(days=1), i + timedelta(days=1)]) | |
camera.snap() | |
else: | |
pass | |
anim = camera.animate(blit=True, interval=100) | |
anim.save("scatter.gif") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment