资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Python可视化库Pandas_Alive怎么使用

这篇文章主要讲解了“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怎么使用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


本文题目:Python可视化库Pandas_Alive怎么使用
网页网址:http://cdkjz.cn/article/pseces.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220