首頁 > 軟體

Python繪製地理圖表視覺化神器pyecharts

2022-07-04 22:00:55

地圖

這期文章我們一起來看看地圖是如何繪製的,如何在地圖裡面新增資料進行多維度的展示,下面我們一起來感受一下地圖的魅力吧!

“地圖就是依據一定的數學法則,使用製圖語言,通過製圖綜合,在一定的載體上,表達地球(或其他天體)上各種事物的空間分佈、聯絡及時間中的發展變化狀態的圖形. 地圖的特徵包括:由於特殊的數學法則而產生的可量測性;由於使用符號表象事物而產生的直觀性;由於製圖綜合而產生的一覽性. 地圖的三要素是:比例尺、方向、圖例 地圖學是研究地圖的理論、編制技術與應用方法的科學,是一門研究以地圖圖形反映與揭示各種自然和社會現象空間分佈、相互聯絡及動態變化的科學、技術與藝術相結合的科學.”

讀萬卷書不如行萬里路,讓我們一起看看祖國的大好山河吧!

地圖模板系列

中國地圖

展示中國的所有省份,一個完全的中國簡單的地理圖形,方便你理解城市的分佈位置喲!

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map()
.add("城市", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
.set_global_opts(title_opts=opts.TitleOpts(title="中國地圖"))
.render("中國地圖.html")
)
print([list(z) for z in zip(Faker.provinces, Faker.values())])

省份資料地圖(重慶地圖)

重慶地圖的展示,新增了區縣的資料即可,快來看看重慶有哪些好玩的地方吧,聽說主城區的洪崖洞還不錯,夜景那是非常好看的,來吧我們一起來看看吧!

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
x=["巫山縣","萬州區","雲陽縣","奉節縣"]
y=[123,560,456,362]
c = (
Map(init_opts=opts.InitOpts(width="1400px", height="700px"))
.add("城市", [list(z) for z in zip(x,y)], "重慶")
.set_global_opts(
title_opts=opts.TitleOpts(title="重慶地圖"), visualmap_opts=opts.VisualMapOpts(max_=560)
)
.render("重慶地圖.html")
)

中國城市地圖資料地圖(分段型)

展示中國省份,提供資料即可,展示分段型的資料按鈕,滑鼠也可以控制喲,快來看看吧!

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map(init_opts=opts.InitOpts(width="1400px", height="700px"))
.add("城市", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="中國人口地圖)"),
visualmap_opts=opts.VisualMapOpts(max_=200, is_piecewise=True),
)
.render("中國分段地圖.html")
)

世界地圖

需要注意的是我們要知道每個國家英文名字,注意和pyecharts的map()語言一樣,不然就不行了。

這裡提供官方對照表喲,這也太強了吧!

{
"Somalia": "索馬利亞",
"Liechtenstein": "列支敦斯登",
"Morocco": "摩洛哥",
"W. Sahara": "西撒哈拉",
"Serbia": "塞爾維亞",
"Afghanistan": "阿富汗",
"Angola": "安哥拉",
"Albania": "阿爾巴尼亞",
"Andorra": "安道爾共和國",
"United Arab Emirates": "阿拉伯聯合大公國",
"Argentina": "阿根廷",
"Armenia": "亞美尼亞",
"Australia": "澳大利亞",
"Austria": "奧地利",
"Azerbaijan": "亞塞拜然",
"Burundi": "蒲隆地",
"Belgium": "比利時",
"Benin": "貝南",
"Burkina Faso": "布吉納法索",
"Bangladesh": "孟加拉國",
"Bulgaria": "保加利亞",
"Bahrain": "巴林",
"Bahamas": "巴哈馬",
"Bosnia and Herz.": "波斯尼亞和黑塞哥維那",
"Belarus": "白俄羅斯",
"Belize": "貝里斯",
"Bermuda": "百慕大",
"Bolivia": "玻利維亞",
"Brazil": "巴西",
"Barbados": "巴貝多",
"Brunei": "汶萊",
"Bhutan": "不丹",
"Botswana": "波札那",
"Central African Rep.": "中非",
"Canada": "加拿大",
"Switzerland": "瑞士",
"Chile": "智利",
"China": "中國",
"Côte d'Ivoire": "象牙海岸",
"Cameroon": "喀麥隆",
"Dem. Rep. Congo": "剛果民主共和國",
"Congo": "剛果",
"Colombia": "哥倫比亞",
"Cape Verde": "維德角",
"Costa Rica": "哥斯大黎加",
"Cuba": "古巴",
"N. Cyprus": "北塞普勒斯",
"Cyprus": "塞普勒斯",
"Czech Rep.": "捷克",
"Germany": "德國",
"Djibouti": "吉布提",
"Denmark": "丹麥",
"Dominican Rep.": "多明尼加",
"Algeria": "阿爾及利亞",
"Ecuador": "厄瓜多",
"Egypt": "埃及",
"Eritrea": "厄利垂亞",
"Spain": "西班牙",
"Estonia": "愛沙尼亞",
"Ethiopia": "衣索比亞",
"Finland": "芬蘭",
"Fiji": "斐濟",
"France": "法國",
"Gabon": "加彭",
"United Kingdom": "英國",
"Georgia": "喬治亞",
"Ghana": "迦納",
"Guinea": "幾內亞",
"Gambia": "甘比亞",
"Guinea-Bissau": "幾內亞比索",
"Eq. Guinea": "赤道幾內亞",
"Greece": "希臘",
"Grenada": "格瑞那達",
"Greenland": "格陵蘭",
"Guatemala": "瓜地馬拉",
"Guam": "關島",
"Guyana": "蓋亞那",
"Honduras": "宏都拉斯",
"Croatia": "克羅埃西亞",
"Haiti": "海地",
"Hungary": "匈牙利",
"Indonesia": "印度尼西亞",
"India": "印度",
"Br. Indian Ocean Ter.": "英屬印度洋領土",
"Ireland": "愛爾蘭",
"Iran": "伊朗",
"Iraq": "伊拉克",
"Iceland": "冰島",
"Israel": "以色列",
"Italy": "義大利",
"Jamaica": "牙買加",
"Jordan": "約旦",
"Japan": "日本",
"Siachen Glacier": "錫亞琴冰川",
"Kazakhstan": "哈薩克",
"Kenya": "肯亞",
"Kyrgyzstan": "吉爾吉斯坦",
"Cambodia": "柬埔寨",
"Korea": "韓國",
"Kuwait": "科威特",
"Lao PDR": "寮國",
"Lebanon": "黎巴嫩",
"Liberia": "賴比瑞亞",
"Libya": "利比亞",
"Sri Lanka": "斯里蘭卡",
"Lesotho": "賴索托",
"Lithuania": "立陶宛",
"Luxembourg": "盧森堡",
"Latvia": "拉脫維亞",
"Moldova": "摩爾多瓦",
"Madagascar": "馬達加斯加",
"Mexico": "墨西哥",
"Macedonia": "馬其頓",
"Mali": "馬裡",
"Malta": "馬耳他",
"Myanmar": "緬甸",
"Montenegro": "黑山",
"Mongolia": "蒙古",
"Mozambique": "莫三比克",
"Mauritania": "茅利塔尼亞",
"Mauritius": "模里西斯",
"Malawi": "馬拉維",
"Malaysia": "馬來西亞",
"Namibia": "納米比亞",
"New Caledonia": "新喀里多尼亞",
"Niger": "尼日",
"Nigeria": "奈及利亞",
"Nicaragua": "尼加拉瓜",
"Netherlands": "荷蘭",
"Norway": "挪威",
"Nepal": "尼泊爾",
"New Zealand": "紐西蘭",
"Oman": "阿曼",
"Pakistan": "巴基斯坦",
"Panama": "巴拿馬",
"Peru": "祕魯",
"Philippines": "菲律賓",
"Papua New Guinea": "巴布亞紐幾內亞",
"Poland": "波蘭",
"Puerto Rico": "波多黎各",
"Dem. Rep. Korea": "朝鮮",
"Portugal": "葡萄牙",
"Paraguay": "巴拉圭",
"Palestine": "巴勒斯坦",
"Qatar": "卡達",
"Romania": "羅馬尼亞",
"Russia": "俄羅斯",
"Rwanda": "盧安達",
"Saudi Arabia": "沙烏地阿拉伯",
"Sudan": "蘇丹",
"S. Sudan": "南蘇丹",
"Senegal": "塞內加爾",
"Singapore": "新加坡",
"Solomon Is.": "索羅門群島",
"Sierra Leone": "獅子山",
"El Salvador": "薩爾瓦多",
"Suriname": "蘇利南",
"Slovakia": "斯洛伐克",
"Slovenia": "斯洛維尼亞",
"Sweden": "瑞典",
"Swaziland": "史瓦濟蘭",
"Seychelles": "塞席爾",
"Syria": "敘利亞",
"Chad": "查德",
"Togo": "多哥",
"Thailand": "泰國",
"Tajikistan": "塔吉克",
"Turkmenistan": "土庫曼",
"Timor-Leste": "東帝汶",
"Tonga": "湯加",
"Trinidad and Tobago": "千里達及托巴哥",
"Tunisia": "突尼西亞",
"Turkey": "土耳其",
"Tanzania": "坦尚尼亞",
"Uganda": "烏干達",
"Ukraine": "烏克蘭",
"Uruguay": "烏拉圭",
"United States": "美國",
"Uzbekistan": "烏茲別克",
"Venezuela": "委內瑞拉",
"Vietnam": "越南",
"Vanuatu": "萬那杜",
"Yemen": "葉門",
"South Africa": "南非",
"Zambia": "尚比亞",
"Zimbabwe": "辛巴威",
"Aland": "奧蘭群島",
"American Samoa": "美屬薩摩亞",
"Fr. S. Antarctic Lands": "南極洲",
"Antigua and Barb.": "安地卡及巴布達",
"Comoros": "葛摩",
"Curaçao": "庫拉索島",
"Cayman Is.": "開曼群島",
"Dominica": "多明尼加",
"Falkland Is.": "馬爾維納斯群島(福克蘭)",
"Faeroe Is.": "法羅群島",
"Micronesia": "密克羅尼西亞",
"Heard I. and McDonald Is.": "赫德島和麥克唐納群島",
"Isle of Man": "曼島",
"Jersey": "澤西島",
"Kiribati": "吉里巴斯",
"Saint Lucia": "聖露西亞",
"N. Mariana Is.": "北馬裡亞納群島",
"Montserrat": "蒙特塞拉特",
"Niue": "紐埃",
"Palau": "帛琉",
"Fr. Polynesia": "法屬波利尼西亞",
"S. Geo. and S. Sandw. Is.": "南喬治亞島和南桑威奇群島",
"Saint Helena": "聖赫勒拿",
"St. Pierre and Miquelon": "聖皮埃爾和密克隆群島",
"São Tomé and Principe": "聖多美和普林西比",
"Turks and Caicos Is.": "特克斯和凱科斯群島",
"St. Vin. and Gren.": "聖文森及格瑞那丁",
"U.S. Virgin Is.": "美屬維爾京群島",
"Samoa": "薩摩亞"
}
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map(init_opts=opts.InitOpts(width="1400px", height="700px"))
.add("國家", [list(z) for z in zip(Faker.country, Faker.values())], "world")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="世界地圖"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
.render("世界地圖.html")
)

中國地圖帶城市(詳細)

如果你想要知道中國地圖,但是也要知道祖國的板塊輪廓,可以用這個模板喲!

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map(init_opts=opts.InitOpts(width="1400px", height="700px"))
.add(
"城市",
[list(z) for z in zip(Faker.guangdong_city, Faker.values())],
"china-cities",
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="中國地圖(帶城市)"),
visualmap_opts=opts.VisualMapOpts(),
)
.render("中國地圖帶城市.html")
)

中國連續資料地圖

之前的那個模板是分段的,這個是連續的資料地圖,看你在什麼場景進行資料視覺化,有需要的這裡都有喲!

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker

c = (
Map(init_opts=opts.InitOpts(width="1400px", height="700px"))
.add("城市", [list(z) for z in zip(Faker.provinces, Faker.values())], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="(標題)"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
.render("連續資料地圖.html")
)

複雜地圖觀賞

到此這篇關於Python繪製地理圖表視覺化神器pyecharts的文章就介紹到這了,更多相關Python繪製神器pyecharts內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!


IT145.com E-mail:sddin#qq.com