работа с файлами форм.Я могу создать карту, но как мне избавиться от краев.в настоящее время они черные код ниже
#https://chrishavlin.com/2016/11/16/shapefiles-tutorial/
#https://gis.stackexchange.com/questions/131716/plot-shapefile-with-matplotlib
#https://stackoverflow.com/questions/30447790/displaying-a-shapefile/48056459#48056459
#https://chrishavlin.com/2016/12/01/shapely-polygons-coloring/
import shapefile
import numpy as np
from matplotlib import pyplot as plt
from descartes import PolygonPatch
from shapely.geometry import Polygon
sf = shapefile.Reader('/Users/francopettigrosso/ws/redisticting_game/python/shapefiles/tr42_d00')
#first feature of the shapefile
print(f'number of shapes imported:{len(sf.shapes())}')
length = len(sf.fields)
for i in range(length):
print(i,sf.fields[i][0])
plt.figure()
ax = plt.axes()
ax.set_aspect('equal')
for shaperec in list(sf.iterShapeRecords()):
shape = shaperec.shape
rec = shaperec.record
print(f"state: {rec[4]} county: {rec[5]} tract: {rec[6]} Name: {rec[7]}")
nparts = len(shape.parts)
if nparts == 1:
polygon = Polygon(shape.points)
patch = PolygonPatch(polygon,facecolor='#56ff02',alpha=1,zorder=1)
patch.set_linewidth= None
patch.set_linewidth= None
ax.add_patch(patch)
else:
for ip in range(nparts):
i0=shape.parts[ip]
if ip < nparts - 1:
i1 = shape.parts[ip+1]-1
else:
i1 = len(shape.points)
polygon = Polygon(shape.points[i0:i1+1])
patch = PolygonPatch(polygon,facecolor=[1,0,0],alpha = 1 , zorder = 1)
patch.set_linewidth= None
patch.set_edgecolor = None
ax.add_patch(patch)
plt.xlim(-81,-74.5)
plt.ylim(39.7,42.5)
plt.show()