Код: Выделить всё
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
#plt.rcParams["animation.html"] = "jshtml"
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(12, 8))
def update(frame):
date = dates[frame]
day_data = daily_groups[date]
ax.scatter(
day_data["Longitude"],
day_data["Latitude"],
s=day_data["TargetValue"],
alpha=0.6,
color="crimson",
edgecolors="black"
)
ax.set_title(f"Confirmed Cases on {date}")
ax.set_xlim([-300, -65])
ax.set_ylim([24, 50])
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.grid(True)
return ax,
anim = FuncAnimation(fig, update, frames=len(dates), interval=200)
plt.tight_layout()
plt.show()
Код: Выделить всё
anim.save("us_cases_animation.mp4", writer="ffmpeg", fps=5)
когда я использую это:
Код: Выделить всё
%matplotlib ipympl
Подробнее здесь: https://stackoverflow.com/questions/797 ... and-vscode