溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何用Python制作地球儀

發布時間:2020-07-31 09:53:05 來源:億速云 閱讀:248 作者:小豬 欄目:開發技術

這篇文章主要為大家展示了如何用Python制作地球儀,內容簡而易懂,希望大家可以學習一下,學習完之后肯定會有收獲的,下面讓小編帶大家一起來看看吧。

Python 功能真的很強,強大到讓人吃驚,它能做的事囊括爬蟲、數據分析、數據可視化、游戲等等各方面,這些功能在實際的使用中應用廣泛,開發程序講究頁面的美觀與炫酷效果, 今天的文章將給各位讀者朋友們帶來不一樣的視覺盛宴,感興趣的朋友歡迎一起嘗試。

寫在前面的話:在之前的文章Python中pyecharts安裝及安裝失敗的解決方法 中有介紹了 pyecharts 的安裝及使用,詳細教程請到官網 學習

pyecharts 功能很強大,只需要導入相應的模塊就配置相應的選項即可生成對應的超文本文件,使用瀏覽器訪問即可!具體實例請見下文

盛宴1-2D世界地圖

先來個 2D 的瞅瞅~

如何用Python制作地球儀

實現代碼如下:

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")
 # 不顯示地圖標志
 .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("world_map.html")
)

盛宴2-中國3D地圖

通過導入 Map3D 等實現中國地圖的 3D 呈現:

如何用Python制作地球儀

實現代碼如下:

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)
 # 全局設置地圖屬性
 .set_global_opts(
 title_opts=opts.TitleOpts(title="全國行政區劃地圖"),
 visualmap_opts=opts.VisualMapOpts(is_show=False),
 tooltip_opts=opts.TooltipOpts(is_show=True),
 )
 .render("map3d_china_base.html")
)

盛宴3-貴州地圖

現在用另一種方式來實現我家鄉的地圖,一起來一睹為快~

如何用Python制作地球儀

代碼實現如下:

# 寫入省份內各地區經緯度
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-地球村實現

一起來看看旋轉的地球吧^^

如何用Python制作地球儀

實現代碼如下:

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 地球示例"),
 # 設置地球屬性
 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")
)

以上就是關于如何用Python制作地球儀的內容,如果你們有學習到知識或者技能,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女