很多数据分析玩家都知道,百度大数据还是非常厉害的,尤其是在绘制地图方面。百度的地图应该使用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.图形展示
效果图:
来源:oschina
链接:https://my.oschina.net/u/3750423/blog/4324976