Fundamentals 5 min read

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.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Creating Smooth Data Visualization Animations with Pynimate in Python

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.5

To 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

animationPythonData visualizationMatplotlibpandasPynimate
Python Programming Learning Circle
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.