pyecharts实现Grid组合图表和Timeline轮播多图

一、源数据

数据来源:国家统计局

二、python程序

import pandas as pd
from pyecharts.charts import Bar
from pyecharts.charts import Map
from pyecharts.charts import WordCloud
from pyecharts.charts import Timeline
from pyecharts.charts import Grid
from pyecharts.globals import SymbolType
from pyecharts import options as opts

data=pd.read_excel('人均可支配收入.xlsx',sheet_name='Sheet1',index_col=0)
x=data.index.tolist()
y=data.values.T.tolist()
year=data.columns.tolist()
y_max=max([max(row) for row in y])
timeline=Timeline(init_opts=opts.InitOpts(width="1500px",height='600px'))

for i in range(len(year)):
    xy=list(zip(x,y[i]))
    xy.sort(key=lambda x:x[1],reverse=False)
    xy_top=xy[-10:]

    bar=Bar()
    bar.add_xaxis(xaxis_data=[i[0] for i in xy])
    bar.add_yaxis('',y_axis=[i[1] for i in xy])
    bar.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-90)),yaxis_opts=opts.AxisOpts(max_=y_max))
    bar.set_series_opts(label_opts=opts.LabelOpts(is_show=True,position='top',rotate=-90))

    map=Map()
    map.add(year[i]+'地区人均可支配收入',data_pair=xy,maptype='china',is_map_symbol_show=False,aspect_scale=0.65)
    map.set_global_opts(title_opts=opts.TitleOpts(title='2005~2021年地区人均可支配收入',subtitle='数据来源:国家统计局'),visualmap_opts=opts.VisualMapOpts(max_=y_max,is_piecewise=True,range_color=['lightskyblue','yellow','orangered']))

    wordcloud=WordCloud()
    wordcloud.add('',xy,word_size_range=[5,45],shape=SymbolType.DIAMOND,is_draw_out_of_bound=False,width='600px',height='180px',pos_left='10px',pos_top='300px')

    grid=Grid()
    grid.add(bar,grid_opts=opts.GridOpts(pos_left='50px',pos_top='80px',width='500px',height='120px'))
    grid.add(map,grid_opts=opts.GridOpts(height='500px'))
    grid.add(wordcloud,grid_opts=opts.GridOpts(height='180px'))

    timeline.add(grid,year[i]).add_schema(is_auto_play=True,pos_left='10%',pos_right='35%')

timeline.render('人均可支配收入.html')

三、效果展示

效果展示

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值