pyecharts中的Map地圖組件可用來地理區域的數據可視化。
1,全國地圖
from pyecharts import Map
value = [155, 10, 66, 78]
attr = ["福建", "山東", "北京", "上海"]
maps = Map(
"全國地圖示例",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
maps.add("",
attr,
value,
maptype='china',
is_label_show=True, # 地圖上顯示省份名稱
is_more_utils=True,
)
maps.render(path="map.html")
結果:
2,結合VisualMap使用
from pyecharts import Map
value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6, 66]
attr = [
"福建", "山東", "北京", "上海", "甘肅", "新疆", "河南", "廣西", "西藏", "內蒙古"
]
maps = Map(
"全國地圖 Map 結合 VisualMap示例",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
maps.add(
"",
attr,
value,
maptype="china",
is_visualmap=True,
visual_text_color="#000",
visual_range=[0, 200],
is_label_show=True, # 地圖上顯示省份名稱
is_more_utils=True,
)
maps.render(path="maps.html")
結果如圖:
3,廣東省地圖:
from pyecharts import Map
value = [20, 190, 253, 77, 65]
attr = ['汕頭市', '汕尾市', '揭陽市', '陽江市', '肇慶市']
maps = Map(
"廣東地圖 Map 結合 VisualMap示例",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
maps.add(
"",
attr,
value,
maptype="廣東",
is_visualmap=True,
visual_text_color="#000",
visual_range=[0, 300],
is_label_show=True,
is_map_symbol_show=True, # 是否顯示地圖標記紅點,默認爲 True
is_more_utils=True,
)
maps.render(path="maps.html")
結果如圖:
4,廣東省肇慶市地圖:
from pyecharts import Map
quxian_distribution = {'端州區': 67, '鼎湖區': 28, '廣寧縣': 22, '懷集縣': 22,
'封開縣': 21, '德慶縣': 18, '高要區': 28, '四會市': 38}
quxian = list(quxian_distribution.keys())
values = list(quxian_distribution.values())
maps = Map(
"廣東省肇慶市地圖 Map 結合 VisualMap示例",
title_color="#fff",
title_pos="center",
width=1200,
height=600,
background_color="#404a59",
)
maps.add(
"",
quxian,
values,
maptype="肇慶",
is_visualmap=True,
visual_text_color="#000",
visual_range=[0, 70],
is_label_show=True,
is_map_symbol_show=True, # 是否顯示地圖標記紅點,默認爲 True
is_more_utils=True,
)
maps.render(path="maps.html")
結果如圖:
注意:Map中無法繪製帶有漣漪特效的動態散點圖。
5,設置 pieces
自定義 visualMap 組件標籤
from pyecharts import Map
data = [
("新疆", 9), ("西藏", 12), ("內蒙古", 32), ("黑龍江", 24), ("吉林", 36), ("遼寧", 55), ("河南", 86), ("河北", 95),
("北京", 16), ("上海", 27), ("天津", 20), ("重慶", 49), ("四川", 56), ("雲南", 66), ("廣東", 73), ("福建", 55)
]
maps = Map(
"全國主要城市空氣質量",
"data from pm2.5",
title_color="#fff",
title_pos="left",
width=1200,
height=600,
background_color="#404a59",
)
attr, value = maps.cast(data)
maps.add(
"",
attr,
value,
maptype="china",
is_visualmap=True,
visual_text_color="#000",
visual_range_text=["", ""],
# visual_range=[0, 100],
is_piecewise=True,
pieces=[
{"max": 100, "min": 70, "label": "高數值"},
{"max": 69, "min": 30, "label": "中數值"},
{"max": 29, "min": 0, "label": "低數值"},
],
is_label_show=True,
is_map_symbol_show=True, # 是否顯示地圖標記紅點,默認爲 True
is_more_utils=True,
)
maps.render(path="maps.html")
結果如圖:
參考:
http://pyecharts.org/#/zh-cn/charts_base?id=map%EF%BC%88%E5%9C%B0%E5%9B%BE%EF%BC%89