- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating animated GIF files out of D3.js animations in Matplotlib
To create animated GIF files out of D3.js animation, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create a new figure or activate an existing figure.
- Add an axes to the current figure and make it the current axes.
- Plot a line with empty lists.
- To initialize the line, pass empty lists.
- To animate the sine curve, update the sine curve values and return the line instance.
- Get a movie writer instance using PillowWriter() class.
- Save the .gif file using PillowWriter.
Example
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)
Output
- Related Articles
- Creating animated loading skeletons in React JS
- How to display animated gif images in Android?
- How to display animated GIF images in Android using Kotlin?
- Saving scatterplot animations with matplotlib
- Creating a Particle Animation in React JS
- Creating a Customizable Modal in React JS
- Creating a QR Code of a link in React JS
- Creating an Airbnb Rheostat Slider in React JS
- Creating a Rich Text Editor in React JS
- Creating Animated Counter using HTML, CSS, and JavaScript
- Plotting animated quivers in Python using Matplotlib
- Creating an Excel-like data grid in React JS
- Plot animated text on the plot in Matplotlib
- How to use external “.js” files in an HTML file?
- How to plot an animated image matrix in matplotlib?

Advertisements