日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

得到经纬度数据使用Plotly画世界地图(美赛心得)

發布時間:2023/12/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 得到经纬度数据使用Plotly画世界地图(美赛心得) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

因為做到一個題是關于亞馬遜的起火問題,需要使用經度維度和其他數據,于是需要針對緯度和經度做一個世界地圖可視化,為大家提供一個思路吧

使用plotly的map模塊https://plotly.com/python/maps/可以做許多類型的圖,一般都是需要在地圖上畫點,可以使用px.scatter_mapbox函數,給出一個官方的例子

px.set_mapbox_access_token(open(".mapbox_token").read()) #為了得到讀取token的權限 df = px.data.carshare() fig = px.scatter_mapbox(df, lat="centroid_lat", lon="centroid_lon", color="peak_hour", size="car_hours",color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10) fig.show()

其中的地圖類型有許多種(參考:https://zhuanlan.zhihu.com/p/87163211)
使用style參數可以改變不同類型的地圖

fig.update_layout(mapbox = {'style':'stamen-terrain'},showlegend =True)


basic類型

plotly對有經緯度的dataframe類型還是很好畫的,如果需要畫大致分布的地圖,可以使用px.density_mapbox函數,下面是我根據2020年亞太賽畫出的一個火災圖,大家可以參考一下,其實plotly官網的教程是很全面的,很多地圖都可以看上面的教程畫出來

import pandas as pd import plotly.graph_objects as go import plotly import geopandas as gpd import plotly.express as pxpd.set_option('display.max_columns', 1000) pd.set_option('display.max_colwidth', 1000) #draw the picture of fire fire = pd.read_csv('fire_archive_M6_168910.csv') #如果 fire_test = pd.read_csv('fire_nrt_M6_168910.csv') fire_test['type']=0 fire=pd.concat([fire,fire_test],axis=0) fire['year'] = fire['acq_date'].apply(lambda x:x[0:7]) year_fire = fire.groupby(['longitude','latitude'])['type'].count() print(year_fire.sort_values().value_counts()) #發生了火災的地方還會不會發生 : 不會 fire= fire[fire['type']==0] #除去異常值 fire['month'] = fire['acq_date'].apply(lambda x:x[0:7]) fire['year'] = fire['acq_date'].apply(lambda x:x[0:4]) fire = fire[fire['year']=='2014'] #找到所有2020的值1 import plotly.express as px fig=px.density_mapbox(lon=fire.longitude,lat=fire.latitude,z=fire.brightness*5,radius=fire.scan,zoom=1,center=dict(lat=-12.14, lon=-55.078),title='The visualization of Amazon') #使用date進行 fig.update_geos(lataxis_showgrid=True, lonaxis_showgrid=True) fig.update_layout(mapbox_style="stamen-terrain") fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0}) fig.show() fig.write_html('9_month_result_visual.html')

效果圖:

總結

以上是生活随笔為你收集整理的得到经纬度数据使用Plotly画世界地图(美赛心得)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。