Creating Smooth Data Visualization Animations with Pynimate in Python
This article introduces the Python package Pynimate, explains how to install it from PyPI, prepares pandas‑style time‑series data, uses the Barplot function with interpolation parameters to generate smooth animated bar charts, and shows how to export the result as GIF or MP4.
Data‑visualization animations no longer need to be built with Excel; a simple Python package can create smooth, high‑quality animated charts in minutes.
Pynimate is a Python library published on PyPI that provides a Barplot class for animating bar‑chart data. After installing the package, you can import it with import pynimate as nim. import pynimate as nim The input data must be a pandas DataFrame where the time column is set as the index, representing the independent variable.
time, col1, col2, col3
2012 1 2 1
2013 1 1 2
2014 2 1.5 3
2015 2.5 2 3.5To create an animated bar chart, call Barplot() with three required arguments: data, time_format (e.g., "%Y-%m-%d"), and ip_freq (interpolation frequency). The ip_freq parameter linearly interpolates between time points to increase frame count and smoothness.
import pandas as pd
df = pd.read_csv('data.csv').set_index('time')Example code that builds a DataFrame, sets the index, creates a canvas, adds a bar plot, and animates it:
from matplotlib import pyplot as plt
import pandas as pd
import pynimate as nim
df = pd.DataFrame({
"time": ["1960-01-01", "1961-01-01", "1962-01-01"],
"Afghanistan": [1, 2, 3],
"Angola": [2, 3, 4],
"Albania": [1, 2, 5],
"USA": [5, 3, 4],
"Argentina": [1, 4, 5]
}).set_index("time")
cnv = nim.Canvas()
bar = nim.Barplot(df, "%Y-%m-%d", "2d")
bar.set_time(callback=lambda i, datafier: datafier.data.index[i].year)
cnv.add_plot(bar)
cnv.animate()
plt.show()To export the animation, use Canvas.save() with the desired filename, frame rate, and format ("gif" or "mp4"). For MP4 output, installing ffmpeg-python or the system ffmpeg binary is recommended.
cnv.save("file", 24, "gif")
# or
cnv.save("file", 24, "mp4")The article also includes example GIFs demonstrating the effect of different interpolation intervals and provides QR‑code links for free Python learning resources.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
