Skip to content

Instantly share code, notes, and snippets.

@MauricioLetelier
Created February 1, 2021 19:54
Show Gist options
  • Save MauricioLetelier/c52a0576b54c5ef7722b4a24bf01339d to your computer and use it in GitHub Desktop.
Save MauricioLetelier/c52a0576b54c5ef7722b4a24bf01339d to your computer and use it in GitHub Desktop.
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