Python可视化各省近20年地区生产总值数据

Python可视化各省近20年地区生产总值数据!

1,数据展示

在这里插入图片描述

2,代码绘图

# -*- coding: utf-8 -*-
#@Project filename:PythonDemo  time_bar.py
#@IDE   :IntelliJ IDEA
#@Author :ganxiang
#@Date   :2020/05/20 0020 10:06


import pandas as pd
from pyecharts.charts import Timeline,Bar
from pyecharts import options as opts
from pyecharts.globals import ThemeType


def time_bar():
    df1 =pd.read_csv("./各省近20年地区生产总值数据.csv",engine='python')
    #width="1450px",height="600px"
    timeLine2=Timeline(init_opts=opts.InitOpts(theme=ThemeType.LIGHT,width="1450px",height="600px"))
    #一,经过数据处理的时间图
    #思路:读取数据,因为数据是杂乱的,需要进行排序处理
    #1,读取数据并出入字典 2,对字典中的数据按value排序可升序降序排序 3,取出排序好的数据进行画时间图
    for i in range(2018,1999,-1):
        m=0#通过m的改变获取每一列的值
        dd={}#存储地区和数据
        for k in range(1,32):
            data =df1[str(i)+"年"].head(k)[m]
            region =df1["地区"].head(k)[m]
            m+=1
            dd[region]=data
        #对字典按值进行排序,升序排序
        sortList = sorted(dd.items(),key = lambda x:x[1],reverse = False)
        region=[]#接收key
        data=[]#接受values
        for k,n in sortList:
            region.append(k)
            data.append(n)
        bar=(
            Bar()
                .add_xaxis(list(region))
                .add_yaxis("近20年各省生产总值(单位:亿元)",list(data))
                .reversal_axis()
                .set_series_opts(label_opts=opts.LabelOpts(position="right"))  # 系列配置项
                .set_global_opts(
                # toolbox_opts=opts.ToolboxOpts(),
                title_opts=opts.TitleOpts("{}年各省生产总值".format(i)),
                xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=0,font_size=12,interval=0)),
                yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=0,font_size=12,interval=0)),
               
            )
        )
        timeLine2.add_schema(play_interval=800)
        timeLine2.add(bar,"{}年".format(i))
    timeLine2.render("./time_bar.html")
    return timeLine2

if __name__=='__main__':
    time_bar()

3,效果展示

在这里插入图片描述

  • 8
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值