繁体   English   中英

在 matplotib 和 geopandas 中注释 xy 点

[英]Annotating xy points in matplotib and geopandas

我正在尝试使用 Geopandas 在地图上注释一些点,但我的问题与 matplotlib 更相关。

我为我的 xy 创建了一列坐标点,但在尝试多种方法时收到以下警告。

ValueError: ('not enough values to unpack (expected 2, got 1)', 'occurred at index 0')

在此处输入图片说明

我要注释的文本是 id 号 (pod_id_location),我只是想在它们各自的点旁边(或上)绘制这些数字,以便在地图上绘制时可以看到哪些 id 对应于哪个点。 我正在尝试使用 lambda apply 将这些值从一列映射到另一列中的坐标。 我看不出我哪里出错了,并且在使用 for 循环时遇到了同样的错误。 感谢您的指点,我的数据和代码如下:

    pod_id_location geometry    Zone
0   1245    POINT (-22993.152 6728924.970)  non-ULEZ
7940    2245    POINT (-13406.652 6714132.654)  ULEZ
13934   3245    POINT (-16958.244 6720147.066)  non-ULEZ
25068   5245    POINT (-20791.698 6699568.057)  non-ULEZ
32551   6245    POINT (-40049.413 6704610.464)  non-ULEZ
... ... ... ...
849223  742451  POINT (-12923.302 6720129.538)  non-ULEZ
849547  832450  POINT (-6445.287 6717978.299)   non-ULEZ
851190  872450  POINT (-4064.943 6697346.893)   non-ULEZ
852852  892450  POINT (6744.514 6713063.033)    non-ULEZ
853523  982450  POINT (-958.349 6706975.535)    non-ULEZ
ax = gdf_2[gdf_2['Zone'] == 'ULEZ'].plot(figsize=(10, 8))

gdf_2.apply(lambda x: ax.annotate(s=x.pod_id_location, xy=x.geometry), axis=1)

plt.axis('off')
plt.show()

我设法通过将我的 lambda 函数更改为这个来解决这个问题:

gdf_2.apply(lambda x: ax.annotate(s=x.pod_id_location, xy=x.loc['geometry'].coords[0]), axis=1)

由于 shapley 对象的第一个元素是坐标。 出于某种原因,我的情节现在打印得很小……但那是我需要解决的问题……

暂无
暂无

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

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