使用文檔:https://jackmckew.github.io/pandas_alive/
當(dāng)可視化一個DataFrame時,如何可視化庫確實(shí)是一個頭疼的事情。今天我們來學(xué)習(xí)一下,pandas_alive。
如果需視頻的話,也可以借助moviepy 視頻處理模塊,把GIF圖片轉(zhuǎn)換為mp4文件。
pandas_alive是一個用于創(chuàng)建動畫圖形的Python庫,它基于matplotlib繪圖庫。該庫主要用于方便快速進(jìn)行動畫可視化制作,尤其適用于處理時間序列數(shù)據(jù)。
在使用pandas_alive進(jìn)行動畫可視化時,需要滿足一定的數(shù)據(jù)格式要求:每行表示單個時間段,每列包含特定類別的值,索引包含時間組件(可選)。
支持水平條形圖、垂直條形圖、比賽、條形圖與時間與x軸一起顯示的折線圖以及餅圖等。此外,它還支持單個可視化中的多個動畫圖表。

圖片展示
導(dǎo)入數(shù)據(jù)分析常用的包
按照模塊pip install pandas_alive
import pandas as pd
import matplotlib.pyplot as plt
import pandas_alive
plt.rcParams ['font.sans-serif'] ='SimHei' #顯示中文
plt.rcParams ['axes.unicode_minus']=False
讀取數(shù)據(jù)集轉(zhuǎn)化為pandas數(shù)據(jù)框?qū)ο螅?/p>
mydata = pd.read_excel('data_source.xlsx')

「生成動態(tài)條形圖」
mydataa=pd.pivot_table(mydata, index="year")

pivot()函數(shù),通過給定的索引(index)和列(column)的值重新生一個DataFrame對象。根據(jù)列值對數(shù)據(jù)進(jìn)行整形(生成一個透視表)。
「生成動態(tài)柱形圖」
增加參數(shù) orientation='v',生成動態(tài)柱形圖。
mydataa=pd.pivot_table(mydata, index="year")
mydataa.plot_animated("bar1.gif", period_fmt="%Y", title="Data",n_visible=10, orientation='v')

****「生成動態(tài)折線圖」****
mydataa.plot_animated(**"bar2.gif"**, period_fmt=**"%Y"**, title=**"Data"**, kind=**'line'**, period_label={**'x'**:0.25, **'y'**:0.9})

******「動態(tài)累積bar」******
mydataa.plot_animated(filename=**'example-pie-chart.gif'**, kind=**"pie"**,rotatelabels=**True**, period_label={**'x'**: 0, **'y'**: 0})

動態(tài)氣泡圖、動態(tài)面積圖、動態(tài)散點(diǎn)圖、動態(tài)累積bar需要獲取對應(yīng)的數(shù)據(jù)才能方便展示
03小結(jié)
運(yùn)用廣泛,是否方便使用呢,后續(xù)在研究,有什么問題可以與我聯(lián)系!
