Skip to main content

Animated plotting extension for Pandas with Matplotlib

Project description

Pandas-Alive

Animated plotting extension for Pandas with Matplotlib

Pandas-Alive is intended to provide a plotting backend for animated matplotlib charts for Pandas DataFrames, similar to the already existing Visualization feature of Pandas.

With Pandas-Alive, creating stunning, animated visualisations is as easy as calling:

df.plot_animated()

Example Bar Chart

Installation

Install with pip install pandas-alive

Usage

As this package builds upon bar_chart_race, the example data set is sourced from there.

Must begin with a pandas DataFrame containing 'wide' data where:

  • Every row represents a single period of time
  • Each column holds the value for a particular category
  • The index contains the time component (optional)

The data below is an example of properly formatted data. It shows total deaths from COVID-19 for the highest 20 countries by date.

Example Data Table Example Table

To produce the above visualisation:

  • Check Requirements first to ensure you have the tooling installed!
  • Call plot_animated() on the DataFrame
    • Either specify a file name to write to with df.plot_animated(filename='example.mp4') or use df.plot_animated().get_html5_video to return a HTML5 video
  • Done!
import pandas_alive

df = pandas_alive.load_dataset()

df.plot_animated(filename='example-barh-chart.gif')

Currently Supported Chart Types

pandas-alive current supports:

Horizontal Bar Charts

import pandas_alive

df = pandas_alive.load_dataset()

df.plot_animated(filename='example-barh-chart.gif')

Example Barh Chart

Vertical Bar Charts

import pandas_alive

df = pandas_alive.load_dataset()

df.plot_animated(filename='example-barv-chart.gif',orientation='v')

Example Barv Chart

Line Charts

With as many lines as data columns in DataFrame.

import pandas_alive

df = pandas_alive.load_dataset()

df.diff().fillna(0).plot_animated(filename='example-line-chart.gif',kind='line')

Example Line Chart

Multiple Charts

pandas-alive supports multiple animated charts in a single visualisation.

  • Create each chart type ensure to disable writing to file with write_to_file=False
  • Create a list of all charts to include in animation
  • Use animate_multiple_plots with a filename and the list of charts (this will use matplotlib.subplots)
  • Done!
import pandas_alive

df = pandas_alive.load_dataset()

animated_line_chart = df.diff().fillna(0).plot_animated(kind='line',write_to_file=False,period_length=200)

animated_bar_chart = df.plot_animated(kind='barh',write_to_file=False,period_length=200)

pandas_alive.animate_multiple_plots('example-bar-and-line-chart.gif',[animated_bar_chart,animated_line_chart]

Example Bar & Line Chart

Inspiration

The inspiration for this project comes from:

Requirements

If you get an error such as TypeError: 'MovieWriterRegistry' object is not an iterator, this signals there isn't a writer library installed on your machine.

This package utilises the matplotlib.animation function, thus requiring a writer library.

Ensure to have one of the supported tooling software installed prior to use!

Contributing

Pull requests are welcome! Please help to cover more and more chart types!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandas_alive-0.1.3.tar.gz (11.1 kB view hashes)

Uploaded Source

Built Distribution

pandas_alive-0.1.3-py3-none-any.whl (12.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page