Skip to content

Instantly share code, notes, and snippets.

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