【发布时间】:2018-08-25 16:19:07
【问题描述】:
我想绘制包含在 geopandas 数据框的单行中的几何图形,但我遇到了问题。这里是一个例子
import geopandas as gpd
import numpy as np
from shapely.geometry import Polygon
p1 = Polygon([(0, 0), (1, 0), (1, 1)])
p2 = Polygon([(2, 0), (3, 0), (3, 1), (2, 1)])
p3 = Polygon([(1, 1), (2, 1), (2, 2), (1, 2)])
index = np.random.random(3)
df = gpd.GeoDataFrame()
df['index'] = index
df['geometry'] = [p1,p2,p3]
df = df.set_geometry('geometry')
现在,如果我使用命令 df.plot() 进行绘图,我会得到 p>
但如果我尝试只绘制一行,df.loc[:,0].plot()
我收到以下错误
TypeError: Empty 'DataFrame': no numeric data to plot,
如果我尝试一下
df.loc[:,'geometry'].plot()
我收到AttributeError: 'Polygon' object has no attribute 'plot'
这样做的正确方法是什么?
【问题讨论】: