Created
February 1, 2021 19:54
-
-
Save MauricioLetelier/c52a0576b54c5ef7722b4a24bf01339d 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-17") & (new.index <= "2021-01-23")] | |
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