#๐Ÿ”’ Saved animation appears to run less frames per second than the one showed on the plot window

9 messages ยท Page 1 of 1 (latest)

safe skiff
#
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
from matplotlib.animation import PillowWriter

fig, axis = plt.subplots()

X = np.linspace(1, 10, 100)
Y = np.sin(X)
X_len = len(X)

def update(frame):
    if frame == 0:
        axis.clear()
    axis.plot(X[:frame], Y[:frame])
    axis.set_xlim(0, 10)
    axis.set_ylim(-3, 3)

animation = animation.FuncAnimation(fig = fig, func = update, frames = X_len, interval = 1)
animation.save("my_animation.gif", writer = PillowWriter(fps = 60))
plt.show()

This is my code. Can someone explain to me why the saved animation appears to be slower than the animation that shows up in the window produced by plt.show()?

stable vergeBOT
#

@safe skiff

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

dusky island
#

discord's gif thing, tenor, hosts mp4 videos even though they're colloquially called gifs, because they loop and are have no audio

#

if you can't export directly to a video, maybe you can export frames, and then put combine them to make the video

safe skiff
#

I saved it as an MP4 file and it worked.

stable vergeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.