# Pandas-Alive
Animated plotting extension for Pandas with Matplotlib
**Pandas-Alive** is intended to provide a plotting backend for animated [matplotlib](https://matplotlib.org/) charts for [Pandas](https://pandas.pydata.org/) DataFrames, similar to the already [existing Visualization feature of Pandas](https://pandas.pydata.org/pandas-docs/stable/visualization.html).
With **Pandas-Alive**, creating stunning, animated visualisations is as easy as calling:
``` python
df.plot_animated()
```
![Example Bar Chart](examples/example-barh-chart.gif)
## Installation
Install with `pip install pandas-alive`
## Usage
As this package builds upon [`bar_chart_race`](https://github.com/dexplo/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](https://raw.githubusercontent.com/dexplo/bar_chart_race/master/images/wide_data.png)
[Example Table](examples/example_dataset_table.md)
To produce the above visualisation:
- Check [Requirements](#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!
``` python
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](#horizontal-bar-charts)
- [Vertical Bar Charts](#vertical-bar-charts)
- [Line Charts](#line-charts)
#### Horizontal Bar Charts
``` python
import pandas_alive
df = pandas_alive.load_dataset()
df.plot_animated(filename='example-barh-chart.gif')
```
![Example Barh Chart](examples/example-barh-chart.gif)
#### Vertical Bar Charts
``` python
import pandas_alive
df = pandas_alive.load_dataset()
df.plot_animated(filename='example-barv-chart.gif',orientation='v')
```
![Example Barv Chart](examples/example-barv-chart.gif)
#### Line Charts
With as many lines as data columns in DataFrame.
``` python
import pandas_alive
df = pandas_alive.load_dataset()
df.diff().fillna(0).plot_animated(filename='example-line-chart.gif',kind='line')
```
![Example Line Chart](examples/example-line-chart.gif)
### 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!
``` python
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](examples/example-bar-and-line-chart.gif)
## Inspiration
The inspiration for this project comes from:
- [bar_chart_race](https://github.com/dexplo/bar_chart_race) by [Ted Petrou](https://github.com/tdpetrou)
- [Pandas-Bokeh](https://github.com/PatrikHlobil/Pandas-Bokeh) by [Patrik Hlobil](https://github.com/PatrikHlobil)
## 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](https://matplotlib.org/3.2.1/api/animation_api.html), thus requiring a writer library.
Ensure to have one of the supported tooling software installed prior to use!
- [ffmpeg](https://ffmpeg.org/)
- [ImageMagick](https://imagemagick.org/index.php)
- [Pillow](https://pillow.readthedocs.io/en/stable/)
- See more at <https://matplotlib.org/3.2.1/api/animation_api.html#writer-classes>
## Contributing
Pull requests are welcome! Please help to cover more and more chart types!
程序员Chino的日记
- 粉丝: 3743
- 资源: 5万+
最新资源
- c++ 回调函数的简单说明 示例
- 2024年福建师范大学学生体质健康测试要求及实施办法解析
- 开源PLC梯形图编译软件
- 低压 无感BLDC方波方案 适用于直流无刷电机 具备脉冲注入功能,识别电机转子初始位置 (ipd) 清单:原理图,丝印图,源代码(没有封库),调试说明文档 keil5.25编译,主控芯片为stm
- screenshot.py
- SIP RFC2543完整协议介绍
- ZB45电气简化图册2
- 基于MFC 开发的c++项目 - 扫雷游戏-2025
- 西门子S7-1500暖通空调冷水机组PLC程序案例, 硬件采用西门子1500CPU+ET200SP接口IO模块,HMI采用西门子触摸屏 程序采用SCL控制程序编程,系统水泵采用一用一备,通过程序实现
- ZB45机组红色故障信息
- docker-oracle-11g
- 大二-Linux基础-老师PPT.7z
- C++-基于MFC的文件管理器.-2025
- 2024 Linux基础课程-涵盖Ubuntu编程环境、数据库、Web服务器及Docker配置实践
- 异步电机与同步电机的控制算法仿真模型大合集 1.PMSM矢量控制模型 2.感应异步电机的间接转子磁场定向控制 3.感应异步电机的有速度传感器矢量控制 4.感应异步电机的直接转矩控制 5.感应异步电机无
- 微博数据(用户信息,好友关系,转发关系).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈