【问题标题】:Map not displayed when plotting points绘制点时不显示地图
【发布时间】:2019-02-11 20:57:38
【问题描述】:

我正在尝试使用 geopandas 将这些点绘制到地图上,但是当我绘制这些点时,地图消失了。

fp = "./nyu_2451_34490/nyu_2451_34490.shp"

map_df = gpd.read_file(fp)

map_df = map_df.to_crs(epsg=4326)

geometry = [Point(x) for x in zip(df['longitude'], df['latitude'])]

gdf = gpd.GeoDataFrame(df, crs = {'init': 'epsg:4326'}, geometry=geometry)

没有点地图会显示

fig, ax = plt.subplots(figsize=(20, 20))
base = map_df.plot(ax=ax, color='gray')
# gdf.plot(ax=ax, markersize=5)

但是当我这样做时

fig, ax = plt.subplots(figsize=(20, 20))
base = map_df.plot(ax=ax, color='gray')
gdf.plot(ax=ax, markersize=5)

【问题讨论】:

  • 你能给出gdf的定义吗?
  • @BrunoCarballo 更新
  • 看秤;我猜,地图还在​​,但它非常小

标签: python matplotlib geopandas


【解决方案1】:

如果shape文件中有经纬度,用scatter来绘制点怎么样?

plt.scatter("longitude", "latitude", data=df)

此外,点的比例似乎不同,或者绘图显示的区域太宽。设置 x 和 y 轴的限制可能会有所帮助。

#set_xlim(left, right)
ax.set_xlim(-74.3, -73.6)
#set_ylim(bottom, top)
ax.set_ylim(40.4, 50.0)

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 2017-04-16
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多