Python源码示例:descartes.PolygonPatch()
示例1
def plot_filled_polygons(self,polygons, facecolour='green', edgecolour='black', linewidth=1, alpha=0.5):
"""
This function plots a series of shapely polygons but fills them in
Args:
ax_list: list of axes
polygons: list of shapely polygons
Author: FJC
"""
from shapely.geometry import Polygon
from descartes import PolygonPatch
from matplotlib.collections import PatchCollection
print('Plotting the polygons...')
#patches = []
for key, poly in polygons.items():
this_patch = PolygonPatch(poly, fc=facecolour, ec=edgecolour, alpha=alpha)
self.ax_list[0].add_patch(this_patch)
示例2
def PlotPolygons(Polygons, Map=None, Ax=None, OutlineColour='k', FillColour='w', ColourMap="None", alpha=0.5):
"""
Function to plot polygons from a shapely Polygon Dictionary
Modified from PlottingRaster.py code by FJC
Outline colour can be name, tuple or range of value to shade
MDH
"""
#create a figure if one doesnt already exist?
if Ax == None:
print("PlotPolygons: Warning, no axes provided, creating new figure and axes")
Fig = plt.figure()
Ax = plt.gca()
plt.axis('equal')
plt.xlabel('Longitude ($^o$)')
plt.ylabel('Latitude ($^o$)')
# convert to map coordinates
if Map != None:
Polygons = ConvertPolygonsLatLong2MapCoords(Polygons, Map)
# loop through shapes in polygons and plot patches
for Key, Poly in Polygons.iteritems():
if Poly.geom_type == 'Polygon':
Patch = PolygonPatch(Poly,fc=FillColour,ec=OutlineColour,alpha=alpha)
Ax.add_patch(Patch)
elif Poly.geom_type == 'MultiPolygon':
for singlepoly in Poly:
Patch = PolygonPatch(singlepoly,fc=FillColour,ec=OutlineColour,alpha=alpha)
Ax.add_patch(Patch)
if Ax == None:
Ax.autoscale_view()
示例3
def plot_polygon(ax,polygon):
# fig = plt.figure(figsize=(10,10))
# ax = fig.add_subplot(111)
# margin = .3
# x_min, y_min, x_max, y_max = polygon.bounds
# ax.set_xlim([x_min-margin, x_max+margin])
# ax.set_ylim([y_min-margin, y_max+margin])
patch = PolygonPatch(polygon, fc='#999999',
ec='#000000', fill=True,
zorder=-1)
ax.add_patch(patch)
return
示例4
def plot_polygon(polygon):
fig = pl.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
margin = .3
print(polygon)
x_min, y_min, x_max, y_max = polygon.bounds
ax.set_xlim([x_min - margin, x_max + margin])
ax.set_ylim([y_min - margin, y_max + margin])
patch = PolygonPatch(polygon, fc='#999999',
ec='#000000', fill=True,
zorder=-1)
ax.add_patch(patch)
return fig