我正在尝试创建示例地图的图表。我将地图的 x 和 y 顶点输入到一个数组中,然后执行
import matplotlib.pyplot as plt
import numpy as np
import math
import pandas as pd
import seaborn as sns
from scipy import *
from scipy.spatial import Voronoi, voronoi_plot_2d
#reads shapefile of region
cities = gpd.read_file('belgian_cities.shp')
#plots the cities
cities.plot()
cities.plot(cmap = 'jet')
g = [i for i in cities.geometry]
x,y = g[0].exterior.coords.xy
all_coords = np.dstack((x,y)) ####
for interior in g[0].interiors: # for first feature/row
x, y = interior.coords.xy
coords = np.dstack((x,y))
all_coords = np.append(all_coords, coords, axis=0)
vor = Voronoi(all_coords)
fig = voronoi_plot_2d(vor)
plt.show()
但是,当我运行代码时,我收到两个错误:
AttributeError:“NoneType”对象没有“关闭”属性
ValueError:缓冲区的维数错误(预期为 2,得到 3)
这是我第一次与 GeoPandas 和 Voronoi 合作,所以如果有人能看一看,那就太好了。
当前结果: