From 6d8318e5f55bdad56e5861b22aec1c164981bd08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Sat, 16 Dec 2023 13:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...13\350\257\225\351\242\234\350\211\262.py" | 42 +- ...\350\211\262\346\265\213\350\257\225.html" | 5202 +++++++++++++++++ 2 files changed, 5217 insertions(+), 27 deletions(-) create mode 100644 "09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\351\242\234\350\211\262\346\265\213\350\257\225.html" diff --git "a/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/12_\346\265\213\350\257\225\351\242\234\350\211\262.py" "b/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/12_\346\265\213\350\257\225\351\242\234\350\211\262.py" index 69c9a11..8787c83 100644 --- "a/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/12_\346\265\213\350\257\225\351\242\234\350\211\262.py" +++ "b/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/12_\346\265\213\350\257\225\351\242\234\350\211\262.py" @@ -1,6 +1,3 @@ -""" -演示第三个图表:GDP动态柱状图开发 -""" from pyecharts.charts import Bar, Timeline from pyecharts.options import * from pyecharts.globals import ThemeType @@ -14,12 +11,8 @@ data_lines = f.readlines() f.close() # 删除第一条数据 data_lines.pop(0) -# 将数据转换为字典存储,格式为: -# { 年份: [ [国家, gdp], [国家,gdp], ...... ], 年份: [ [国家, gdp], [国家,gdp], ...... ], ...... } -# { 1960: [ [美国, 123], [中国,321], ...... ], 1961: [ [美国, 123], [中国,321], ...... ], ...... } # 先定义一个字典对象 data_dict = {} -bar_colors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#00FFFF', '#FF00FF', '#C0C0C0', '#800080'] for line in data_lines: year = (line.split(",")[0]) # 日期 country = line.split(",")[1] # 昵称 @@ -31,11 +24,12 @@ for line in data_lines: data_dict[year] = [] data_dict[year].append([country, gdp]) -# print(data_dict[1960]) # 创建时间线对象 -timeline = Timeline({"theme": ThemeType.LIGHT}) +timeline = Timeline() +# timeline = Timeline({"theme": ThemeType.ROMANTIC}) # 排序年份 sorted_year_list = sorted(data_dict.keys()) + for year in sorted_year_list: data_dict[year].sort(key=lambda element: element[1], reverse=True) # 取出本年份前8名的国家 @@ -50,34 +44,28 @@ for year in sorted_year_list: bar = Bar() x_data.reverse() y_data.reverse() - - # bar.add_xaxis(x_data) - # for i, (country, gdp,color) in enumerate(zip(x_data, y_data,bar_color_list)): - # bar.add_yaxis( - # series_name=country, - # yaxis_data=[gdp], - # label_opts=opts.LabelOpts(position="right", color=bar_color_list[i]), - # ) bar.add_xaxis(x_data) - bar.add_yaxis("红包数据", y_data, label_opts=LabelOpts(position="right")) - # bar.add_yaxis("红包数据", y_data, label_opts=LabelOpts(position="right"), itemstyle_opts=ItemStyleOpts(color=bar_color_list)) - # 反转x轴和y轴 + colors=['rgba(128, 128, 128, 0.5)'] + # colors=['rgba(128, 128, 128, 0.5)','red','red','red','red','red','red','red'] + bar.add_yaxis("红包数据", y_data + , itemstyle_opts=opts.ItemStyleOpts( + # color="red" + color="blue" + ) + , label_opts=LabelOpts(position="right")) + bar.reversal_axis() - # 设置每一天的图表的标题 bar.set_global_opts( - title_opts=TitleOpts(title=f"{year}-CSDN抢到红包累计排名") + title_opts=TitleOpts(title=f"{year}-CSDN抢到红包累计排名"), ) timeline.add(bar, str(year)) -# for循环每一年的数据,基于每一年的数据,创建每一年的bar对象 -# 在for中,将每一年的bar对象添加到时间线中 - # 设置时间线自动播放 timeline.add_schema( - play_interval=2000, + play_interval=1500, is_timeline_show=True, is_auto_play=True, is_loop_play=False ) # 绘图 -timeline.render("2023年11月11-2023年12月15每天CSDN抢到红包累计排名前8用户.html") +timeline.render("颜色测试.html") diff --git "a/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\351\242\234\350\211\262\346\265\213\350\257\225.html" "b/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\351\242\234\350\211\262\346\265\213\350\257\225.html" new file mode 100644 index 0000000..ee00022 --- /dev/null +++ "b/09_\345\217\257\350\247\206\345\214\226\346\241\210\344\276\213/\351\242\234\350\211\262\346\265\213\350\257\225.html" @@ -0,0 +1,5202 @@ + + +
+ +