Last active
February 1, 2021 19:51
-
-
Save MauricioLetelier/17391afb442b67dce10bdd5cbc4ad00e 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 | |
import seaborn as sns | |
from celluloid import Camera | |
from datetime import timedelta | |
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 | |
for idx, i in enumerate(new.index): | |
if idx % 20 == 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", | |
) | |
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