我正在尝试将标签添加到显示平铺地图上的点的 hvplot 中。
我的 GeoDataFramegdf
如下所示:
id geometry
8911 POINT (5.79557 53.20121)
8912 POINT (5.76973 53.18031)
8913 POINT (5.78159 53.20088)
8914 POINT (5.75442 53.20394)
8915 POINT (5.76594 53.21173)
将这些点添加到地图很容易:
gdf.hvplot(geo=True, tiles=True)
然后我尝试使用标签以类似的方式绘制文本标签,但这不起作用。:
gdf.hvplot.labels(geo=True, tiles=True, text='id')
它给了我这个错误
Traceback (most recent call last):
File "<ipython-input-138-73570b6a686e>", line 1, in <module>
centroid_labels = dfl.hvplot.labels(geo=True, tiles=True, text='id')
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\plotting\core.py", line 574, in labels
return self(x, y, text=text, kind='labels', **kwds)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\plotting\core.py", line 79, in __call__
return self._get_converter(x, y, kind, **kwds)(kind, x, y)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\converter.py", line 1097, in __call__
obj = method(x, y)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\converter.py", line 1688, in labels
text = self.kwds.get('text', [c for c in data.columns if c not in (x, y)][0])
IndexError: list index out of range
显式添加x
andy
选项会产生不同的错误:
gdf.hvplot.labels(geo=True, tiles=True, x=gdf.geometry.x, y=gdf.geometry.y, text='id')
Traceback (most recent call last):
File "<ipython-input-143-0eaefd24cbe6>", line 1, in <module>
centroid_labels = dfl.hvplot.labels(geo=True, x=dfl.geometry.x, y=dfl.geometry.y, tiles=True, text='id')
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\plotting\core.py", line 574, in labels
return self(x, y, text=text, kind='labels', **kwds)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\plotting\core.py", line 79, in __call__
return self._get_converter(x, y, kind, **kwds)(kind, x, y)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\hvplot\plotting\core.py", line 83, in _get_converter
x = x or params.pop('x', None)
File "C:\Users\user\Miniconda3\envs\otp\lib\site-packages\pandas\core\generic.py", line 1442, in __nonzero__
raise ValueError(
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().