中国1949至2019年的gdp图表_Python可视化地图:2019年中国各省GDP情况(pyecharts地理图表)...

e72ba780e3977ecea441618e4656ceb8.png

大家好!

今天来分享一下如何用Python工具来帮助我们制作一张展示2019年中国各省GDP的可视化地图。

4934289c766b5f503a0aa39ea223af75.png

案例中数据表格结构如下:

be27a06f870f372efe9955ab2f571e4b.png

代码及演示:

import numpy as np
import pandas as pd
from pyecharts.globals import ThemeType
from pyecharts import options as opts
from pyecharts.charts import Map

df_map = pd.read_excel("D:01会Excel的隔壁老王Excel报表20200506-Python地图可视化:2019年中国各省GDP情况Python地图可视化:2019年中国各省GDP情况.xlsx")

df_map

368f2e2a99b22d03cd26252affcd1ad4.png
c = (
    Map(init_opts=opts.InitOpts(width="1000px", height="600px",theme = ThemeType.DARK))
    .add("2019年中国各省GDP", df_map[["地区","2019年省GDP总量(亿)"]].values.tolist(), "china")
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2019年中国各省GDP总量(亿)(微信公众号:会Excel的隔壁老王)",pos_bottom = "90%", pos_right = "20%"),
        visualmap_opts=opts.VisualMapOpts(type_= "color",max_=110000, range_text = ['GDP总量(亿)颜色区间:', ''],is_piecewise=1,pos_top= "middle",pos_left="left",orient="vertical",split_number=10),
        #tooltip_opts = opts.TooltipOpts(formatter="{c} %")
    )
    #.render("map_visualmap_piecewise.html")
)

c.render_notebook()

4934289c766b5f503a0aa39ea223af75.png

完整python代码参考:

import numpy as np
import pandas as pd
from pyecharts.globals import ThemeType
from pyecharts import options as opts
from pyecharts.charts import Map

df_map = pd.read_excel("D:01会Excel的隔壁老王Excel报表20200506-Python地图可视化:2019年中国各省GDP情况Python地图可视化:2019年中国各省GDP情况.xlsx")

c = (
    Map(init_opts=opts.InitOpts(width="1000px", height="600px",theme = ThemeType.DARK))
    .add("2019年中国各省GDP", df_map[["地区","2019年省GDP总量(亿)"]].values.tolist(), "china")
    .set_global_opts(
        title_opts=opts.TitleOpts(title="2019年中国各省GDP总量(亿)(微信公众号:会Excel的隔壁老王)",pos_bottom = "90%", pos_right = "20%"),
        visualmap_opts=opts.VisualMapOpts(type_= "color",max_=110000, range_text = ['GDP总量(亿)颜色区间:', ''],is_piecewise=1,pos_top= "middle",pos_left="left",orient="vertical",split_number=10),
        #tooltip_opts = opts.TooltipOpts(formatter="{c} %")
    )
    #.render("map_visualmap_piecewise.html")
)

c.render_notebook()
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个关于2019粤港澳地区GDP情况可视化地图案例,同样使用了pyecharts地理图表,并且实现了动态演示数据的效果: ```python import pandas as pd import numpy as np import random from pyecharts import options as opts from pyecharts.charts import Map from pyecharts.faker import Faker from pyecharts.globals import ThemeType from pyecharts.commons.utils import JsCode # 读取数据 data=pd.read_excel('gdp_guangdong_hk_macau.xlsx') # 绘制地图 map=Map() map.add("2019粤港澳地区GDP",list(zip(data['地区'],data['GDP'])), "world",is_map_symbol_show=False) map.set_global_opts(title_opts=opts.TitleOpts(title="2019粤港澳地区GDP情况", subtitle="数据来源:国家统计局"), visualmap_opts=opts.VisualMapOpts(max_=1000000)) # 实现动态效果 values=list(data['GDP']) gdp_max=max(values) gdp_min=min(values) gdp_range=gdp_max-gdp_min def get_random_values(): return [random.randint(gdp_min,gdp_max) for _ in range(len(data))] def update_map(): map.set_series_opts(label_opts=opts.LabelOpts(is_show=True)) map.set_global_opts(visualmap_opts=opts.VisualMapOpts(max_=gdp_range), title_opts=opts.TitleOpts(title="2019粤港澳地区GDP情况", subtitle="数据来源:国家统计局"), graphic_text_opts=opts.GraphicTextOpts( graphic_item=opts.GraphicItem( left="center", top="center" ), graphic_textstyle_opts=opts.GraphicTextStyleOpts( text="数据更新中......", font="bold 20px Microsoft YaHei", graphic_basicstyle_opts=opts.GraphicBasicStyleOpts( fill="rgba(0,0,0,0.3)" ) ) ) ) data['GDP']=get_random_values() map.set_data_pair(list(zip(data['地区'],data['GDP']))) return map.dump_options_with_quotes() # 执行动态效果 map.add_js_funcs("setInterval(function (){" "option="+update_map()+";" "myChart.setOption(option);" "}, 2000);") map.render("gdp_guangdong_hk_macau.html") ``` 这段代码同样读取一个名为"gdp_guangdong_hk_macau.xlsx"的数据文件,其中包含了粤港澳地区的GDP数据。然后使用pyecharts库中的Map类,将数据绘制在地图上。最后使用add_js_funcs()方法实现了动态效果,每隔2秒钟更新一次数据。 这个案例还使用了pyecharts库中的Faker类,用来生成一些假数据。如果您的数据是实时更新的,可以将get_random_values()函数替换为从网站或数据库中获取数据的代码。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值