0

working with shape files. I am able to produce a map, but how do I get rid of the edge colors. they are currently blackenter image description here code below

#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()
Franco Pettigrosso
  • 4,056
  • 2
  • 20
  • 32
  • 1
    I’m not familiar with descartes, but maybe try using `“none”` rather than `None` for the edgecolor setting. `None` often implies you are not making a choice. – RuthC Dec 01 '18 at 17:04
  • Also you probably want `set_edgecolor(“none”)`. At the moment you appear to be replacing a method with `None`. – RuthC Dec 01 '18 at 17:37

0 Answers0