D3.js . में से एनिमेटेड GIF फ़ाइलें बनाने के लिए एनिमेशन, हम निम्नलिखित कदम उठा सकते हैं -
- आकृति का आकार सेट करें और सबप्लॉट के बीच और आसपास पैडिंग समायोजित करें।
- नया आंकड़ा बनाएं या मौजूदा आंकड़ा सक्रिय करें।
- वर्तमान आकृति में एक कुल्हाड़ी जोड़ें और इसे वर्तमान कुल्हाड़ी बनाएं।
- खाली सूचियों वाली एक पंक्ति प्लॉट करें।
- लाइन को इनिशियलाइज़ करने के लिए, खाली सूचियाँ पास करें।
- साइन कर्व को एनिमेट करने के लिए, साइन कर्व मान अपडेट करें और लाइन इंस्टेंस लौटाएं।
- PillowWriter() का उपयोग करके मूवी लेखक का उदाहरण प्राप्त करें कक्षा।
- PillowWriter . का उपयोग करके .gif फ़ाइल सहेजें ।
उदाहरण
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
def init():
line.set_data([], [])
return line,
def animate(i):
x = np.linspace(0, 2, 1000)
y = np.sin(2 * np.pi * (x - 0.01 * i))
line.set_data(x, y)
return line,
ani = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit=True)
writer = animation.PillowWriter(fps=25)
ani.save("sine.gif", writer=writer) आउटपुट
