我正在绘制一些数据,伦敦各地的气象站,并想用气象站的名称标记每个数据点(绿色点),例如Bow,Westminster。
地图是从Geopandas数据框中的geometry列创建的。使用此帖子:
https://stackoverflow.com/questions/14432557/matplotlib-scatter-plot-with-different-text-at-each-data-point
我试图对文本进行批注,但出现以下错误:
TypeError: 'Point' object is not iterable
.
这是目前的地图:
下面是代码:
f, ax = plt.subplots(1, figsize=(12, 12))
ax.set_title('Plot of London Grid for Learning weather stations with London boroughs and locations of Urban Mind datapoints', fontsize = 15)
boroughs.plot(alpha=1,edgecolor='w', facecolor='gray', linewidth=0.1, ax=ax)
london_umdata_geo.plot(ax=ax, marker="o",color="red",markersize=10.0,alpha=1.0, legend=True) #1,015 UM datapoints in London
stations_geo.plot(ax=ax, marker="X",color='green',markersize=20.0,alpha=1.0,legend=True)
n = stations_geo['Station Name'].tolist()
for i, txt in enumerate(n):
ax.annotate(txt, xy = stations_geo.loc[i,'geometry'])
plt.show()
站点为绿色点,其他数据点(不带标签)为红色。
stations_geo
是GeoPandas数据帧,其中包含
geometry
使用matplotlib从中打印点的列。
我对annotate方法使用一个循环,据说循环遍历geometry列中的点,并将这些点用作注释的坐标,但是matplotlib似乎不喜欢点对象(它们是形状点)。但是,这些点直接被用来创建绿色点,所以我不确定哪里出错了。
感谢您的帮助,谢谢!