欢迎光临散文网 会员登陆 & 注册

黑马程序员python教程,8天python从入门到精通,学python看这套就

2023-02-27 05:34 作者:lzyj7897  | 我要投稿

P110


from pyecharts.options import *

from pyecharts.charts import Bar

from pyecharts.globals import ThemeType

from pyecharts.charts import Timeline


with open(r"1960-2019全球GDP数据.csv", 'r', encoding="GB2312") as f:

    lines = f.readlines()

    lines.pop(0)

data = {}

for line in lines:

    year = line.split(',')[0]

    country = line.split(',')[1]

    GDP = float(line.split(',')[2])

    try:

        data[year].append([country, GDP])

    except:

        data[year] = []

        data[year].append([country, GDP])

timeline = Timeline(init_opts=InitOpts(

    theme=ThemeType.ROMA, width="1500px", height="700px", animation_opts=AnimationOpts(animation_duration_update=100)))


for year in data.keys():

    data[year].sort(key=lambda element: element[1], reverse=True)

    bar = Bar().add_yaxis(

        "GDP", [(x[1]/10**8) for x in data[year][:8]][::-1], label_opts=LabelOpts(position="right")).add_xaxis([x[0] for x in data[year][:8][::-1]]).reversal_axis()

    timeline.add(bar, time_point=year)

timeline.add_schema(is_auto_play=True,

                    is_timeline_show=True, play_interval=600)

timeline.render("GDP.html")


黑马程序员python教程,8天python从入门到精通,学python看这套就的评论 (共 条)

分享到微博请遵守国家法律