温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Python可视化库Pandas_Alive怎么使用

发布时间:2021-11-23 16:23:04 来源:亿速云 阅读:384 作者:iii 栏目:大数据

这篇文章主要讲解了“Python可视化库Pandas_Alive怎么使用”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Python可视化库Pandas_Alive怎么使用”吧!

前言

最近发现汉语中类似的一个可视化图库「Pandas_Alive」,不仅包含动态条形图,还可以绘制动态曲线图产品,气泡图,饼状图,地图在等。

同样也是几行代码就能完成动态图表的替换。

GitHub地址:

https://github.com/JackMcKew/pandas_alive

使用文档:

https://jackmckew.github.io/pandas_alive/

安装版本建议是0.2.3 matplotlib版本是3.2.1

同时需自行安装tqdm(显示进度条)和descartes(放置地图相关库)。

要不然会出现报错,估计是作者的requestment.txt没包含这两个库。

好了,成功安装后就可以约会这个第三方库,直接选择加载本地文件。

import  pandas_alive as  pd 
import  pandas  
covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.plot_animated(filename = 'examples / example-barh-chart.gif',n_visible = 15)

刚开始学习这个库的时候,大家可以减少数据,这样生成GIF的时间就会快一些

例如在接下来的实践中,基本都只挑选了20天左右的数据。

Python可视化库Pandas_Alive怎么使用

对于其他图表,我们可以查看官方文档的API说明,得以了解。

下面我们就来看看其他动态图表的替换方法吧!

动态条形图

elec_df = pd.read_csv(“ data / Aus_Elec_Gen_1980_2018.csv”,index_col = 0,parse_dates = [ 0 ],千元= ',')
elec_df = elec_df.iloc [:20,:] elec_df.fillna(0).plot_animated('examples / example-electricity- generation -australia.gif',period_fmt = “%Y”,title = '1980-2018年澳大利亚发电来源')

Python可视化库Pandas_Alive怎么使用

02动态柱状图

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.plot_animated(filename = 'examples / example-barv-chart.gif',方向= 'v',n_visible = 15)

03动态曲线图

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.diff()
fillna(0).plot_animated(filename = 'examples / example-line-chart.gif',kind = 'line',period_label = { 'x':  0.25,  'y':  0.9 })

Python可视化库Pandas_Alive怎么使用

04动态面积图

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.sum(axis = 1).fillna(0).plot_animated(filename = 'examples / example-bar-chart .gif',kind = 'bar',
        period_label = { 'x':  0.1,  'y':  0.9 },
        enable_progress_bar = True,steps_per_period = 2,interpolate_period = True,period_length = 200
)

05动态散点图

max_temp_df = pd.read_csv(
    “ data / Newcastle_Australia_Max_Temps.csv”,
    parse_dates = { “ Timestamp”:[ “ Year”,  “ Month”,  “ Day” ]},
)
min_temp_df = pd.read_csv(
    “ data / Newcastle_Tustralia_T。,
    parse_dates = { “ Timestamp”:[ “ Year”,  “ Month”,  “ Day” ]},
)

max_temp_df = max_temp_df.iloc [:5000
,:] min_temp_df = min_temp_df.iloc [:5000

,:] merged_temp_df = pd。 merge_asof(max_temp_df,min_temp_df,on = “ Timestamp”)
merged_temp_df.index = pd.to_datetime(merged_temp_df [ “ Timestamp” ] .dt.strftime('%Y /%m /%d'))

keep_columns = [ “最低温度(摄氏度)”,  “最高温度(摄氏度)) “ ” 
merged_temp_df [keep_columns] .resample(“ Y”).mean()。plot_animated(filename = 'examples / example-scatter-chart.gif',kind = “ scatter”,
                                                                title = “最高温度和最低温度澳大利亚纽卡斯尔')

Python可视化库Pandas_Alive怎么使用

06动态饼状图

covid_df = pd.read_csv('data / covid19.csv',index_col = 0,parse_dates = [ 0 ])
covid_df.plot_animated(filename = 'examples / example-pie-chart.gif',kind = “ pie”,
                       rotationlabels = True,period_label = { 'x':  0,  'y':  0 })

07动态气泡图

multi_index_df = pd.read_csv( “数据/ multi.csv” ,标题= [ 0,  1 ],index_col = 0)
multi_index_df.index = pd.to_datetime(multi_index_df.index,dayfirst =真)

map_chart = multi_index_df.plot_animated(
    种类= “ bubble”,
    文件名= “ examples / example-bubble-chart.gif”,
    x_data_label = “经度”,
    y_data_label = “纬度”,
    size_data_label = “案例”,
    color_data_label = “案例”,
    vmax = 5,steps_per_period = 3,interpolate_period = True,period_length = 500,
    dpi = 100
)

Python可视化库Pandas_Alive怎么使用

08地理空间点图表

进口 geopandas
导入 pandas_alive
进口 contextily 

GDF = geopandas.read_file('数据/ NSW-covid19-例逐postcode.gpkg' )
gdf.index = gdf.postcode 
GDF = gdf.drop('邮编',轴= 1)

的结果= gdf.iloc [:,:20 ] 
result [ 'geometry' ] = gdf.iloc [:,  -1:] [ 'geometry' ] 

map_chart = result.plot_animated(filename = 'examples / example-geo-point-chart .gif”,
                                 basemap_format = { 'source':contextily.providers.Stamen.Terrain})

09总体地理图表

进口 geopandas
导入 pandas_alive
进口 contextily 

GDF = geopandas.read_file('数据/意大利-covid-region.gpkg' )
gdf.index = gdf.region 
GDF = gdf.drop('区域',轴= 1)

结果= gdf.iloc [:,:20 ] 
result [ 'geometry' ] = gdf.iloc [:,  -1:] [ 'geometry' ] 

map_chart = result.plot_animated(filename = 'examples / example-example-example-geo-polygon-chart.gif',
                                 basemap_format = { 'source':contextily.providers.Stamen.Terrain})

Python可视化库Pandas_Alive怎么使用

感谢各位的阅读,以上就是“Python可视化库Pandas_Alive怎么使用”的内容了,经过本文的学习后,相信大家对Python可视化库Pandas_Alive怎么使用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI