失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【pyecharts库与pandas库】利用pyecharts库根据表格中的GDP数据绘制中国各省GDP

【pyecharts库与pandas库】利用pyecharts库根据表格中的GDP数据绘制中国各省GDP

时间:2022-11-07 20:13:16

相关推荐

【pyecharts库与pandas库】利用pyecharts库根据表格中的GDP数据绘制中国各省GDP

程序解决问题描述:

根据下图表建立中国GDP.csv文件,然后打开文件读取GDP数据,以中国地图显示各省(未包括台湾省)的GDP热力图,用柱状图显示GDP最低的五个省人口和人均GDP的关系。

数据表格截图如下:

数据源自网络仅供参考

在运用程序进行数据处理时需要将上述数据保存为csv文件。

程序代码如下:

from pyecharts import options as optsfrom pyecharts.charts import Mapimport pandas as pdfrom pyecharts.charts import Bar,Pagefile_name = '中国各省份GDP(1).csv'reader = pd.read_csv(file_name, encoding='gbk')prvcnm = reader['省份']gdp = reader[''] # 读取时为字符串,转为float类型数据zhsf=list(reader['省份'].tail(5))zhrk=list(reader['人口'].tail(5))zhrjgdp=list(reader['人均'].tail(5))prvc_gdp_growth = list(zip(prvcnm, gdp))page=Page(layout=Page.DraggablePageLayout)customMap = (Map().add("GDP", # 图例prvc_gdp_growth, # 数据项"china", is_map_symbol_show=False, #).set_series_opts(label_opts=opts.LabelOpts( # 设置标签配置项is_show=True )).set_global_opts(title_opts=opts.TitleOpts( # 设置标题配置项title="中国各省GDP增长地理分布图", # 设置标题名称pos_left="center" , # 设置标题居中),# 设置图例配置项legend_opts=opts.LegendOpts(pos_right="left", # 设置为水平居左pos_bottom="bottom" # 设置为垂直居下),# 设置视觉映射配置项visualmap_opts=opts.VisualMapOpts(max_=90000,min_=10000,is_piecewise=True,pieces=[{"max": 90000, "min": 52000, "label": ">=52000", "color": "#B40404"},{"max": 52000, "min": 32000, "label": "32000-52000", "color": "#DF0101"},{"max": 32000, "min": 16000, "label": "16000-32000", "color": "#F78181"},{"max": 16000, "min": 8000, "label": "8000-16000", "color": "#F5A9A9"},{"max": 8000, "min": 1000, "label": "1000-8000", "color": "#FFFFCC"}])))bar=(Bar().set_global_opts(title_opts=opts.TitleOpts( title="GDP最低的五个省人口和人均GDP", # 设置标题名称pos_left="center", # 设置标题居中),legend_opts=opts.LegendOpts(pos_right="right",pos_left="left",# 设置为水平居左pos_top="top" # 设置为垂直居下),yaxis_opts=opts.AxisOpts(name='人口/万人',offset=10)))bar.add_xaxis(zhsf) # 添加x轴数据bar.add_yaxis('人口/万人',zhrk,yaxis_index=0) # 添加y轴数据bar.add_yaxis('人均GDP',zhrjgdp,yaxis_index=1)bar.extend_axis(yaxis=(opts.AxisOpts(name="人均GDP",min_=0,max_=10,)))page.add(customMap,bar)page.render("demo33.html") # 显示图表

程序运行结果如下:

程序运行结果保存在网页中,用浏览器打开即可。

GDP数据与运行结果仅做学习交流练习使用,使用的地图仅做学习Python程序设计使用,非标准中国地图。

关注博主学习更多python程序设计知识!

【pyecharts库与pandas库】利用pyecharts库根据表格中的GDP数据绘制中国各省GDP热力图和GDP较低的五个省的人均GDP与人口的柱状图

如果觉得《【pyecharts库与pandas库】利用pyecharts库根据表格中的GDP数据绘制中国各省GDP》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。