完整代码:
from pyecharts import options as opts
from pyecharts.charts import Map
import pandas as pd
df = pd.read_excel('各省份GDP.xlsx')
# print(df.head())
year = 2023
info = df[['省份',year]]
# print(info)
info_list = info.values.tolist()
print(info_list)
# 创建一个map对象,用来生成地图
map = Map()
map.add(
series_name='地区生产总值',
data_pair=info_list,
maptype='china',
zoom=1,
)
map.set_global_opts(
title_opts=opts.TitleOpts(
title=f'{year}地区生产总值(亿元)',
subtitle = '数据来源:国家统计局',
pos_right = 'center',
pos_top = '5%',
),
visualmap_opts = opts.VisualMapOpts(
max_= 53617,
min_= 10990,
range_color = ['#1E9600','#FFF200','#FF0000']
)
)
map.render('map.html')
数据展示:
结果展示:
点击某个省份即可查看这个省份的GDP数据