Python 使用Matplotlib打印坐标会扭曲底图
我试图使用Geopandas和Matplotlib在地图上显示商店的空间分布 问题: 绘制管脚时,底图会扭曲。以下是绘制管脚之前和之后的示例 问题: 这种扭曲的根源是什么?我怎样才能预防它Python 使用Matplotlib打印坐标会扭曲底图,python,matplotlib,geopandas,Python,Matplotlib,Geopandas,我试图使用Geopandas和Matplotlib在地图上显示商店的空间分布 问题: 绘制管脚时,底图会扭曲。以下是绘制管脚之前和之后的示例 问题: 这种扭曲的根源是什么?我怎样才能预防它 import pandas as pd import geopandas as gpd import matplotlib.pyplot as plt from shapely.geometry import Polygon # Creating the simplified polygon latitud
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import Polygon
# Creating the simplified polygon
latitude = [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 basemap
ax = polygon.plot(color="#3791CB")
# Dict of sample coordinates
coordinates = {"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 coordinates
df = pd.DataFrame(coordinates)
# Creating the GeoDataFrame
shops = gpd.GeoDataFrame(coordinates, geometry=gpd.points_from_xy(df.longitude, df.latitude))
# Plotting office coordinates
shops.plot(ax=ax, color="red", markersize = 20, zorder=2)
# adding grid
plt.grid(linestyle=":", color='grey')
plt.show()
谢谢大家! 你的地图和图钉有不同的参考系 创建第一个地理数据框时,指定其坐标参照系(crs='epsg:4326')。当您为车间坐标创建地理数据框时,您不会这样做。这就是失真的来源 这应该可以解决它:
shops = gpd.GeoDataFrame(
coordinates,
geometry = gpd.points_from_xy(
df.longitude,
df.latitude),
crs = "EPSG:4326"
)
)
干杯