Python使用pyecharts繪制世界地圖,省級地圖,城市地圖實例詳解
1.世界地圖繪制演示
先給大家看下效果圖哈。
① 世界地圖數(shù)據(jù)準備
地圖數(shù)據(jù)如下:
因為是世界地圖,所以對標的國家,我設置了 2 組,里面的數(shù)據(jù)是隨機生成的。
# -*- coding:utf-8 -*- # 2022-2-14 # 作者:小藍棗 # pyecharts地圖 # 需要引用的庫 from pyecharts import options as opts from pyecharts.charts import Map import random # 設置奧特曼所存在的相關國家,并設置初始數(shù)量為0 ultraman = [ ['Russia', 0], ['China', 0], ['United States', 0], ['Australia', 0] ] # 設置怪獸存在的相關國家,并設置初始數(shù)量為0 monster = [ ['India', 0], ['Canada', 0], ['France', 0], ['Brazil', 0] ] def data_filling(array): ''' 作用:給數(shù)組數(shù)據(jù)填充隨機數(shù) ''' for i in array: # 隨機生成1到1000的隨機數(shù) i[1] = random.randint(1,1000) print(i) data_filling(ultraman) data_filling(monster)
② 世界地圖生成
上面的數(shù)據(jù)代碼,加上下面的地圖生成代碼,合在一起就生成地圖了。
def create_world_map(): ''' 作用:生成世界地圖 ''' ( # 大小設置 Map() .add( series_name="奧特曼", data_pair=ultraman, maptype="world", ) .add( series_name="怪獸", data_pair=monster, maptype="world", ) # 全局配置項 .set_global_opts( # 設置標題 title_opts=opts.TitleOpts(title="世界地圖"), # 設置標準顯示 visualmap_opts=opts.VisualMapOpts(max_=1000, is_piecewise=False), ) # 系列配置項 .set_series_opts( # 標簽名稱顯示,默認為True label_opts=opts.LabelOpts(is_show=False, color="blue") ) # 生成本地html文件 .render("世界地圖.html") ) create_world_map()
運行后會生成一個 html 文件,打開后就可以查看生成的地圖了。
生成的地圖效果圖如下:
2.省份(河北?。┑貓D繪制演示
先給大家看下效果圖哈。
① 省份地圖數(shù)據(jù)準備
地圖數(shù)據(jù)如下:
因為是省份地圖,所以對標的城市,我設置了 2 組,里面的數(shù)據(jù)是隨機生成的。
# -*- coding:utf-8 -*- # 2022-2-14 # 作者:小藍棗 # pyecharts地圖 # 需要引用的庫 from pyecharts import options as opts from pyecharts.charts import Map import random # 設置奧特曼所存在的相關城市,并設置初始數(shù)量為0 ultraman = [ ['承德市', 0], ['邯鄲市', 0], ['石家莊市', 0] ] # 設置怪獸存在的相關城市,并設置初始數(shù)量為0 monster = [ ['張家口市', 0], ['秦皇島市', 0], ['保定市', 0] ] def data_filling(array): ''' 作用:給數(shù)組數(shù)據(jù)填充隨機數(shù) ''' for i in array: # 隨機生成1到1000的隨機數(shù) i[1] = random.randint(1,1000) print(i) data_filling(ultraman) data_filling(monster)
② 省份地圖生成
上面的數(shù)據(jù)代碼,加上下面的地圖生成代碼,合在一起就生成地圖了。
def create_province_map(): ''' 作用:生成省份地圖 ''' ( # 大小設置 Map() .add( series_name="奧特曼", data_pair=ultraman, maptype="河北", ) .add( series_name="怪獸", data_pair=monster, maptype="河北", ) # 全局配置項 .set_global_opts( # 設置標題 title_opts=opts.TitleOpts(title="省份地圖"), # 設置標準顯示 visualmap_opts=opts.VisualMapOpts(max_=1000, is_piecewise=False), ) # 系列配置項 .set_series_opts( # 標簽名稱顯示,默認為True label_opts=opts.LabelOpts(is_show=True, color="blue") ) # 生成本地html文件 .render("省份地圖.html") ) create_province_map()
運行后會生成一個 html 文件,打開后就可以查看生成的地圖了。
生成的地圖效果圖如下:
3.城市(承德市)地圖繪制演示
先給大家看下效果圖哈。
① 城市地圖數(shù)據(jù)準備
地圖數(shù)據(jù)如下:
因為是省份地圖,所以對標的城市,我設置了 2 組,里面的數(shù)據(jù)是隨機生成的。
# -*- coding:utf-8 -*- # 2022-2-14 # 作者:小藍棗 # pyecharts地圖 # 需要引用的庫 from pyecharts import options as opts from pyecharts.charts import Map import random # 設置奧特曼所存在的相關城市,并設置初始數(shù)量為0 ultraman = [ ['雙橋區(qū)', 0], ['隆化縣', 0], ['寬城滿族自治縣', 0] ] # 設置怪獸存在的相關城市,并設置初始數(shù)量為0 monster = [ ['平泉縣', 0], ['豐寧滿族自治縣', 0], ['興隆縣', 0] ] def data_filling(array): ''' 作用:給數(shù)組數(shù)據(jù)填充隨機數(shù) ''' for i in array: # 隨機生成1到1000的隨機數(shù) i[1] = random.randint(1,1000) print(i) data_filling(ultraman) data_filling(monster)
② 城市地圖生成
上面的數(shù)據(jù)代碼,加上下面的地圖生成代碼,合在一起就生成地圖了。
def create_city_map(): ''' 作用:生成城市地圖 ''' ( # 大小設置 Map() .add( series_name="奧特曼", data_pair=ultraman, maptype="承德", ) .add( series_name="怪獸", data_pair=monster, maptype="承德", ) # 全局配置項 .set_global_opts( # 設置標題 title_opts=opts.TitleOpts(title="城市地圖"), # 設置標準顯示 visualmap_opts=opts.VisualMapOpts(max_=1000, is_piecewise=False), ) # 系列配置項 .set_series_opts( # 標簽名稱顯示,默認為True label_opts=opts.LabelOpts(is_show=True, color="blue") ) # 生成本地html文件 .render("城市地圖.html") ) create_city_map()
運行后會生成一個 html 文件,打開后就可以查看生成的地圖了。
生成的地圖效果圖如下:
以上就是Python使用pyecharts繪制世界地圖,省級地圖,城市地圖實例詳解的詳細內(nèi)容,更多關于Python pyecharts繪制地圖的資料請關注腳本之家其它相關文章!
相關文章
django使用sqlite3統(tǒng)計前臺站點訪問數(shù)量示例
這篇文章主要為大家介紹了django使用sqlite3統(tǒng)計前臺站點訪問數(shù)量示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08ndarray數(shù)組的轉(zhuǎn)置(transpose)和軸對換方式
這篇文章主要介紹了ndarray數(shù)組的轉(zhuǎn)置(transpose)和軸對換方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02