I would like to produce a plot of New Zealand with each region colour coded according to some data. However, the shapefiles I have used to produce the image extend beyond the edge of the land and into the ocean. This means that when I colour the polygons they end up colouring portions of the ocean as well. Not the desired response!
The code I am using is:
from mpl_toolkits.basemap import Basemap
from matplotlib.patches import Polygon
plt.figure(figsize=(15,15))
lonmax = 180
lonmin = 165
latmax = -33
latmin = -48
map = Basemap(llcrnrlon=lonmin,llcrnrlat=latmin,urcrnrlon=lonmax,urcrnrlat=latmax, resolution = 'i')
map.drawmapboundary(fill_color='white')
map.fillcontinents(color='white',lake_color='white')
map.drawcoastlines()
map.readshapefile('../data/raw/statsnzregional-council-2016-generalised-version-SHP/regional-council-2016-generalised-version', 'regional_council')
ax = plt.gca() # get current axes instance
cm = matplotlib.cm.get_cmap('viridis')
norm = matplotlib.colors.Normalize(vmin=0.05, vmax=0.35)
for info, shape in zip(map.regional_council_info, map.regional_council):
poly = Polygon(shape, facecolor=cm(norm(region_percent[info['REGC2016_N']])),edgecolor='k')
ax.add_patch(poly)
plt.show()
Which produces the below image. This image is very close to what I want but I would like the colouring to stop at the land boundary rather than colouring the ocean as well.
I have looked into Basemap's maskoceans() and believe this is probably the best way to solve this but I don't understand how to apply it to my particular situation (eg, how to access the lat,lons? What is the data array in this case?)
Alternatively is there a way to make the map boundary of New Zealand a hard boundary so only the interior overlap with the polygon patches is printed?
