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()
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.
To produce the above visualisation:
- Set
output_file
for the visualisations to write to, or useoutput_html
to return a HTML5 video - Call
plot_animated()
on the DataFrame - Done!
import pandas_alive
df = pandas_alive.load_dataset()
pandas_alive.output_file('example-barh-chart.gif')
df.plot_animated()
Currently Supported Chart Types
pandas-alive
current supports:
Horizontal Bar Charts
import pandas_alive
df = pandas_alive.load_dataset()
pandas_alive.output_file('example-barh-chart.gif')
df.plot_animated()
Vertical Bar Charts
import pandas_alive
df = pandas_alive.load_dataset()
pandas_alive.output_file('example-barv-chart.gif')
df.plot_animated(orientation='v')
Line Charts
With as many lines as data columns in DataFrame.
import pandas_alive
df = pandas_alive.load_dataset()
pandas_alive.output_file('example-line-chart.gif')
df.diff().plot_animated(kind='line')
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 afilename
and the list of charts (this will usematplotlib.subplots
) - Done!
import pandas_alive
df = pandas_alive.load_dataset()
animated_line_chart = df.diff().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]
Inspiration
The inspiration for this project comes from:
Contributing
Pull requests are welcome! Please help cover more and more chart types!
Requirements
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pandas_alive-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f78d62f6f8fd167fdf70f8389a6cb4bb5dc2ac18b605f13b2fd60a0dcc2422c1 |
|
MD5 | 594ccf84760685adf5a20c254749750f |
|
BLAKE2b-256 | e0ecbc8a54ec0796be6a1ff13ca09a74063efc127cd7abbce48d0968c34d2a94 |