【问题标题】:cannot align subplots when plotting geopandas dataframes绘制 geopandas 数据框时无法对齐子图
【发布时间】:2019-07-31 22:52:42
【问题描述】:

我正在尝试绘制公交车站的 geopandas 数据框(形状文件(多边形)的另一个数据框上的形状点。我可以单独绘制它们,但是当我尝试将它们分层时,我无法让这些图对齐正确。

# Convert the dataframe into a geodataframe
gdf = gpd.GeoDataFrame(unique_stops.drop(['lat', 'lng'], axis=1), crs={'init': 'esri:102003'}, geometry=[Point(xy) for xy in zip(unique_stops.lat, unique_stops.lng)])

# read in the city shapefile
base = gpd.read_file('https://opendata.arcgis.com/datasets/89f1a70c0cf24d7692e2d02fdf8f4e47_0.geojson')
base.to_crs(crs={'init': 'esri:102003'}, inplace=True)

# Setup figure and axis with different size
f, ax = plt.subplots(1)

# Add layer of polygons on the axis
base.plot(ax=ax)
gdf.plot(ax=ax)

# Display
plt.show()

我希望这些地块相互叠加。但是,目前的输出如下:

我相信这可能是因为数据框几何图形的 x 轴和 y 轴可能相互颠倒,但我不知道如何明确指定。

【问题讨论】:

  • 我宁愿猜测数据是在完全不同的坐标系中指定的(类似于正弦波在辐射和度数之间的不同)。大多数情况下,在绘制地理数据时会使用转换,但无法知道此处是否缺少转换,因为该示例不是minimal reproducible example
  • 我觉得你应该切换经纬度

标签: python matplotlib geopandas


【解决方案1】:

这确实是一个经纬度被颠倒以及 CRS 不匹配的问题。

【讨论】:

    猜你喜欢
    • 2016-11-10
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多