简体   繁体   English

绘制点时不显示地图

[英]Map not displayed when plotting points

I'm trying to plot the points onto a map with geopandas but when I do plot the points the map disappears. 我正在尝试将点绘制到带有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)

Without the points the map does show up 没有点,地图就会显示出来

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

But when I do 但是当我这样做

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

If it has longitude and latitude in shape file, how about using scatter to plot the points? 如果形状文件中有经度和纬度,如何使用散点图绘制点?

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

In addition, it looks like the points have different scale or the plot is showing too wide area. 此外,看起来这些点的比例不同或该图显示的区域太宽。 Setting the limit of x and y axis may help. 设置x和y轴的极限可能会有所帮助。

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM