用 Python 制作地球儀的方法
Python 功能真的很強(qiáng),強(qiáng)大到讓人吃驚,它能做的事囊括爬蟲、數(shù)據(jù)分析、數(shù)據(jù)可視化、游戲等等各方面,這些功能在實際的使用中應(yīng)用廣泛,開發(fā)程序講究頁面的美觀與炫酷效果, 今天的文章將給各位讀者朋友們帶來不一樣的視覺盛宴,感興趣的朋友歡迎一起嘗試。
寫在前面的話:在之前的文章Python中pyecharts安裝及安裝失敗的解決方法 中有介紹了 pyecharts 的安裝及使用,詳細(xì)教程請到官網(wǎng) 學(xué)習(xí)
pyecharts 功能很強(qiáng)大,只需要導(dǎo)入相應(yīng)的模塊就配置相應(yīng)的選項即可生成對應(yīng)的超文本文件,使用瀏覽器訪問即可!具體實例請見下文
盛宴1-2D世界地圖
先來個 2D 的瞅瞅~

實現(xiàn)代碼如下:
from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
c = (
Map(init_opts=opts.InitOpts(width='1500px', height='1200px',bg_color='#E0EEEE'))
# 加載世界地圖實例
.add("世界地圖", [list(z) for z in zip(Faker.country, Faker.values())], "world")
# 不顯示地圖標(biāo)志
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
# 配置項標(biāo)題設(shè)置
title_opts=opts.TitleOpts(title="世界地圖示例"),
visualmap_opts=opts.VisualMapOpts(max_=200)
)
# 生成超文本文件
.render("world_map.html")
)
盛宴2-中國3D地圖
通過導(dǎo)入 Map3D 等實現(xiàn)中國地圖的 3D 呈現(xiàn):

實現(xiàn)代碼如下:
from pyecharts import options as opts
from pyecharts.charts import Map3D
from pyecharts.globals import ChartType
c = (
Map3D(init_opts=opts.InitOpts(width='1300px', height='1300px',bg_color='#EBEBEB'))
.add_schema(
itemstyle_opts=opts.ItemStyleOpts(
color="#CDBA96",
opacity=1,
border_width=0.8,
border_color="rgb(62,215,213)",
),
map3d_label=opts.Map3DLabelOpts(
is_show=True,
text_style=opts.TextStyleOpts(
color="#104E8B", font_size=16, background_color="rgba(0,0,0,0)"
),
),
emphasis_label_opts=opts.LabelOpts(is_show=True),
light_opts=opts.Map3DLightOpts(
main_color="#FFEBCD",
main_intensity=1.2,
is_main_shadow=False,
main_alpha=55,
main_beta=10,
ambient_intensity=0.3,
),
)
.add(series_name="", data_pair="", maptype=ChartType.MAP3D)
# 全局設(shè)置地圖屬性
.set_global_opts(
title_opts=opts.TitleOpts(title="全國行政區(qū)劃地圖"),
visualmap_opts=opts.VisualMapOpts(is_show=False),
tooltip_opts=opts.TooltipOpts(is_show=True),
)
.render("map3d_china_base.html")
)
盛宴3-貴州地圖
現(xiàn)在用另一種方式來實現(xiàn)我家鄉(xiāng)的地圖,一起來一睹為快~

代碼實現(xiàn)如下:
# 寫入省份內(nèi)各地區(qū)經(jīng)緯度
example_data = [
[[106.70722,26.59820, 1000],[106.63024, 26.64702, 1000]],
[[104.83023, 26.59336], [106.92723, 27.72545]],
[[105.30504, 27.29847], [107.52034, 26.29322]],
[[107.89868, 26.52881], [104.948571, 25.077502]],
[[105.9462, 26.25367], [109.18099, 27.69066]],
]
# 添加 3D 地圖
c = (
Map3D(init_opts=opts.InitOpts(width='1200px', height='1200px'))
.add_schema(
maptype="貴州",
itemstyle_opts=opts.ItemStyleOpts(
color="rgb(5,101,123)",
opacity=1,
border_width=0.8,
border_color="rgb(62,215,213)",
),
light_opts=opts.Map3DLightOpts(
main_color="#fff",
main_intensity=1.2,
is_main_shadow=True,
main_alpha=55,
main_beta=10,
ambient_intensity=0.3,
),
view_control_opts=opts.Map3DViewControlOpts(center=[-10, 0, 10]),
post_effect_opts=opts.Map3DPostEffectOpts(is_enable=True),
)
.add(
series_name="",
data_pair=example_data,
type_=ChartType.LINES3D,
effect=opts.Lines3DEffectOpts(
is_show=True,
period=4,
trail_width=3,
trail_length=0.5,
trail_color="#f00",
trail_opacity=1,
),
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(title_opts=opts.TitleOpts(title="Map3D-GuiZhou3D"))
.render("guizhou_map_3d.html")
)
盛宴4-地球村實現(xiàn)
一起來看看旋轉(zhuǎn)的地球吧^^

實現(xiàn)代碼如下:
import pyecharts.options as opts
from pyecharts.charts import MapGlobe
from pyecharts.faker import POPULATION
data = [x for _, x in POPULATION[1:]]
low, high = min(data), max(data)
c = (
MapGlobe(init_opts=opts.InitOpts(width='1000px', height='1000px',bg_color='#FFFAFA',))
.add_schema()
.add(
maptype="world",
series_name="World Population",
data_pair=POPULATION[1:],
is_map_symbol_show=True,
label_opts=opts.LabelOpts(is_show=True),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="3D 地球示例"),
# 設(shè)置地球?qū)傩?
visualmap_opts=opts.VisualMapOpts(
min_=low,
max_=high,
range_text=["max", "min"],
is_calculable=True,
range_color=["lightskyblue", "yellow", "orangered"],
)
)
.render("world_map_3d.html")
)
總結(jié)
希望今天的分享能給大家?guī)聿灰粯拥囊曈X享受,同時伙伴們也別忘了要多多實踐。 實踐是檢驗真理的唯一標(biāo)準(zhǔn)!
參考
http://gallery.pyecharts.org/#/Map3D/
示例代碼 (https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Earth_view )
到此這篇關(guān)于用 Python 制作地球儀的方法的文章就介紹到這了,更多相關(guān)python 地球儀內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在unittest中使用 logging 模塊記錄測試數(shù)據(jù)的方法
今天小編就為大家分享一篇在unittest中使用 logging 模塊記錄測試數(shù)據(jù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11
Django REST Swagger實現(xiàn)指定api參數(shù)
這篇文章主要介紹了Django REST Swagger實現(xiàn)指定api參數(shù),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
Python?Pandas?中的數(shù)據(jù)結(jié)構(gòu)詳解
這篇文章主要介紹了Python?Pandas?中的數(shù)據(jù)結(jié)構(gòu)詳解,Pandas有三種數(shù)據(jù)結(jié)構(gòu)Series、DataFrame和Panel,文章圍繞主題展開更多相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-06-06
Pytorch自動求導(dǎo)函數(shù)詳解流程以及與TensorFlow搭建網(wǎng)絡(luò)的對比
PyTorch是一個開源的Python機(jī)器學(xué)習(xí)庫,基于Torch,用于自然語言處理等應(yīng)用程序。2017年1月,由Facebook人工智能研究院(FAIR)基于Torch推出了PyTorch,這篇文章主要介紹了Pytorch自定義自動求導(dǎo)函數(shù),以及PyTorch與TensorFlow搭建網(wǎng)絡(luò)的對比2021-11-11
Python使用itchat模塊實現(xiàn)群聊轉(zhuǎn)發(fā),自動回復(fù)功能示例
這篇文章主要介紹了Python使用itchat模塊實現(xiàn)群聊轉(zhuǎn)發(fā),自動回復(fù)功能,結(jié)合實例形式分析了Python基于itchat模塊針對微信信息的發(fā)送、回復(fù)等相關(guān)操作技巧,需要的朋友可以參考下2019-08-08
如何使用yolov5輸出檢測到的目標(biāo)坐標(biāo)信息
YOLOv5是一系列在 COCO 數(shù)據(jù)集上預(yù)訓(xùn)練的對象檢測架構(gòu)和模型,下面這篇文章主要給大家介紹了關(guān)于如何使用yolov5輸出檢測到的目標(biāo)坐標(biāo)信息的相關(guān)資料,需要的朋友可以參考下2022-03-03

