亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Matplotlib 繪制坐標會扭曲底圖

使用 Matplotlib 繪制坐標會扭曲底圖

開滿天機 2023-05-09 10:33:12
我正在嘗試使用 Geopandas 和 Matplotlib 在地圖上顯示商店的空間分布。問題: 當我繪制圖釘時,底圖會變形。這是繪制引腳之前和之后的示例問題: 這種失真的來源是什么?我該如何預防?import pandas as pdimport geopandas as gpdimport matplotlib.pyplot as pltfrom shapely.geometry import Polygon# Creating the simplified polygonlatitude = [60.41125, 59.99236, 59.99236]longitude = [24.66917, 24.66917, 25.36972]geometry = Polygon(zip(longitude, latitude))polygon = gpd.GeoDataFrame(index=[0], crs = 'epsg:4326', geometry=[geometry]) # ploting  the basemapax = polygon.plot(color="#3791CB")# Dict of sample coordinatescoordinates = {"latitude": ["60.193141", "60.292777", "60.175053", "60.163187", "60.245272", "60.154392", "60.182906"],"longitude": ["24.934214", "24.969730", "24.831068", "24.739044", "24.860983", "24.884773", "24.959175"]}# Creating a dataframe from coordinatesdf = pd.DataFrame(coordinates)# Creating the GeoDataFrameshops = gpd.GeoDataFrame(coordinates, geometry=gpd.points_from_xy(df.longitude, df.latitude))# Plotting office coordinatesshops.plot(ax=ax, color="red", markersize = 20, zorder=2)# adding gridplt.grid(linestyle=":", color='grey')plt.show()謝謝你!
查看完整描述

1 回答

?
哆啦的時光機

TA貢獻1779條經驗 獲得超6個贊

你的地圖和別針有不同的參考系統..


當您創建第一個 GeoDataFrame 時,您指定其坐標參考系統 (crs = 'epsg:4326')。當您為商店坐標創建地理數據框時,您不需要。這就是失真的來源……


這應該修復它:


shops = gpd.GeoDataFrame(

        coordinates, 

        geometry = gpd.points_from_xy(

              df.longitude, 

              df.latitude), 

              crs = "EPSG:4326" 

              )

        ) 


查看完整回答
反對 回復 2023-05-09
  • 1 回答
  • 0 關注
  • 165 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號