我可以使用以下代码读取geoJSON文件,然后将其成功绘制在图中。图中的每个补丁都有灰色边框。每个补丁都有组名。我可以从geoJSON文件本身获取此名称。
现在,我想向具有相同组名的补丁组添加另一个红色边框,并在组的中间显示组名。我该怎么办?
import matplotlib.pyplot as plt
from descartes import PolygonPatch
import simplejson as json
json_data = []
with open('LKA_adm2-2.json') as f:
json_data = json.load(f)
fig = plt.figure(figsize=(3.841, 7.195), dpi=100)
ax = fig.gca()
for section in json_data["features"]:
#multiple sections will have same group_name.
#based on this name I want to create a collection of sections and draw a border for it.
group_name = section["properties"]["NAME"]
ax.add_patch(PolygonPatch(section["geometry"], fc="#ffffff", ec='#9C9C9C', alpha=1, zorder=2, lw=0.2 ))
plt.show()
PS:组始终相邻
谢谢:)