Python笔记:模拟百度大数据,绘制一幅“广州春运期间人口迁徙图”

若如初见. 提交于 2020-08-11 02:45:40

        很多数据分析玩家都知道,百度大数据还是非常厉害的,尤其是在绘制地图方面。百度的地图应该使用JavaScript来做的,而我选择Python。其实两者可能同宗。

# 1.导入相关的库
from pyecharts.charts import Geo
import pyecharts.options as opts

# 2.模拟数据
city_num = [("广州",105),("成都",70),("北京",99),
            ("西安",80),("杭州",60),("贵阳",34),
            ("上海",65),("深圳",54),("乌鲁木齐",76),
            ("哈尔滨",47),("兰州",56),("信阳",85)]
start_end = [("广州","成都"),("广州","北京"),("广州","西安"),
             ("广州","杭州"),("广州","贵阳"),("广州","上海"),
             ("广州","深圳"),("广州","乌鲁木齐"),("广州","哈尔滨"),
             ("广州","兰州"),("广州","信阳")]

( 
    # 3.初始化地图类
    Geo(init_opts = opts.InitOpts(width = "800px",height = "500px",theme = "blue"))
    .add_schema(maptype = "china", 
                itemstyle_opts=opts.ItemStyleOpts(color = "#323c48", border_color = "black"))  #接壤处颜色
    # 4.添加数据
    .add("哈佛在等我呢~", data_pair = city_num, color = "white")
    .add("", data_pair = start_end, type_ = "lines",label_opts = opts.LabelOpts(is_show = False),
         effect_opts = opts.EffectOpts(symbol = "arrow",  #辐射的形状
                                     color = "green",  #改变箭头的颜色
                                     symbol_size = 8))
    .set_global_opts(
        title_opts = opts.TitleOpts(title = "广州春运人口迁徙图"),
        visualmap_opts = opts.VisualMapOpts(min_ = 30, max_ = 110))
).render_notebook()  # 5.图形展示

效果图:

 

 

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!