如何將pyecharts中geo地圖的默認顯示經緯度改爲地名

districts=['北京','上海','廣州','深圳']
value = [500,500,500,500]

geo =Geo("一線城市","",width=800, height=700, title_pos='center',title_top=10, title_color="#2E2E2E",
         subtitle_color='#aaa',title_text_size=16,subtitle_text_size=12,background_color='#EEEEE8',
         page_title='Echarts',renderer='canvas',is_animation=True)

geo.add("", 
        districts, value,type="effectScatter",is_selected=True,symbol='circle',symbol_size=20,color=None,
        maptype ='china',is_roam=True,is_visualmap=False, visual_range=[0,500],visual_text_color="#2E2E2E",
        geo_normal_color="#323c48",geo_emphasis_color='#2a033d', effect_scale=3,
        is_label_show=True,label_text_color="#00FF00",label_pos="inside"
        )
 
#geo.render("一線城市.html")
geo

在這裏插入圖片描述
如上圖,默認顯示的標籤是經緯度,想要改爲地名,需要添加參數label_formatter可以進行設置,label_formatter說明如下。
label_formatter -> str
模板變量有 {a}, {b},{c},{d},{e},分別表示系列名,數據名,數據值等。使用示例,如 label_formatter=’{a}’
在 trigger 爲 ‘axis’ 的時候,會有多個系列的數據,此時可以通過 {a0}, {a1}, {a2} 這種後面加索引的方式表示系列的索引。不同圖表類型下的 {a},{b},{c},{d} 含義不一樣。 其中變量 {a}, {b}, {c}, {d} 在不同圖表類型下代表數據含義爲:

折線(區域)圖、柱狀(條形)圖、K線圖 : {a}(系列名稱),{b}(類目值),{c}(數值), {d}(無)
散點圖(氣泡)圖 : {a}(系列名稱),{b}(數據名稱),{c}(數值數組), {d}(無)
地圖 : {a}(系列名稱),{b}(區域名稱),{c}(合併數值), {d}(無)
餅圖、儀表盤、漏斗圖: {a}(系列名稱),{b}(數據項名稱),{c}(數值), {d}(百分比)
根據上面的說明,在add中添加label_formatter=’{b}'即可

districts=['北京','上海','廣州','深圳']
value = [500,500,500,500]

geo =Geo("一線城市","",width=800, height=700, title_pos='center',title_top=10, title_color="#2E2E2E",
         subtitle_color='#aaa',title_text_size=16,subtitle_text_size=12,background_color='#EEEEE8',
         page_title='Echarts',renderer='canvas',is_animation=True)

geo.add("", 
        districts, value,type="effectScatter",is_selected=True,symbol='circle',symbol_size=20,color=None,
        maptype ='china',is_roam=True,is_visualmap=False, visual_range=[0,500],visual_text_color="#2E2E2E",
        geo_normal_color="#323c48",geo_emphasis_color='#2a033d', effect_scale=3,label_formatter='{b}',
        is_label_show=True,label_text_color="#00FF00",label_pos="inside"
        )
 
#geo.render("一線城市.html")
geo

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章