I want to plot the Canadian shapefile with province boundaries highlighted and hollow filling.
I have downloaded the shapefile from here.
This is the script I use to visualize the shapefile:
import shapefile import matplotlib.pyplot as plt import matplotlib.patches as patches from matplotlib.patches import Polygon from matplotlib.collections import PatchCollection # -- input -- sf = shapefile.Reader("myfolder\gpr_000a11a_e.shp") recs = sf.records() shapes = sf.shapes() Nshp = len(shapes) cns =  for nshp in xrange(Nshp): cns.append(recs[nshp]) cns = array(cns) cm = get_cmap('Dark2') cccol = cm(1.*arange(Nshp)/Nshp) # -- plot -- fig = plt.figure() ax = fig.add_subplot(111) for nshp in xrange(Nshp): ptchs =  pts = array(shapes[nshp].points) prt = shapes[nshp].parts par = list(prt) + [pts.shape] for pij in xrange(len(prt)): ptchs.append(Polygon(pts[par[pij]:par[pij+1]])) ax.add_collection(PatchCollection(ptchs,facecolor=cccol[nshp,:],edgecolor='k', linewidths=.1)) ax.set_xlim(-160,-40) ax.set_ylim(40,90)
The output is confusing, in that the Northern border is completely wrong and it does not resemble the real one. I think there are unwanted lines that connect points far away from each other. As a result, the islands in Northern Nunavut have been merged in a single polygon. How to obtain a neat border?