本文整理汇总了Python中matplotlib.patches.Polygon.set_zorder方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.set_zorder方法的具体用法?Python Polygon.set_zorder怎么用?Python Polygon.set_zorder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Polygon
的用法示例。
在下文中一共展示了Polygon.set_zorder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fillwaterbodies
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_zorder [as 别名]
def fillwaterbodies(basemap, color='blue', inlands=True, ax=None, zorder=None):
"""
Fills the water bodies with color.
If inlands is True, inland water bodies are also filled.
Parameters
----------
basemap : Basemap
The basemap on which to fill.
color : {'blue', string, RGBA tuple}, optional
Filling color
inlands : {True, False}, optional
Whether inland water bodies should be filled.
ax : {None, Axes instance}, optional
Axe on which to plot. If None, the current axe is selected.
zorder : {None, integer}, optional
zorder of the water bodies polygons.
"""
if not isinstance(basemap, Basemap):
raise TypeError, "The input basemap should be a valid Basemap object!"
#
if ax is None and basemap.ax is None:
try:
ax = pyplot.gca()
except:
import matplotlib.pyplot as pyplot
ax = pyplot.gca()
basemap.ax = ax
#
coastpolygons = basemap.coastpolygons
coastpolygontypes = basemap.coastpolygontypes
(llx, lly) = (basemap.llcrnrx, basemap.llcrnry)
(urx, ury) = (basemap.urcrnrx, basemap.urcrnry)
background = Polygon([(llx, lly), (urx, lly), (urx, ury), (llx, ury)])
#
ogr_background = polygon_to_geometry(background)
inland_polygons = []
#
for (poly, polytype) in zip(coastpolygons, coastpolygontypes):
if polytype != 2:
verts = ["%s %s" % (x, y) for (x, y) in zip(*poly)]
ogr_poly = ogr.CreateGeometryFromWkt("POLYGON ((%s))" % ','.join(verts))
ogr_background = ogr_background.Difference(ogr_poly)
else:
inland_polygons.append(Polygon(zip(*poly),
facecolor=color,
edgecolor=color,
linewidth=0))
#
background = geometry_to_vertices(ogr_background)
for xy in background:
patch = Polygon(xy, facecolor=color, edgecolor=color, linewidth=0)
if zorder is not None:
patch.set_zorder(zorder)
ax.add_patch(patch)
#
if inlands:
for poly in inland_polygons:
if zorder is not None:
poly.set_zorder(zorder)
ax.add_patch(poly)
basemap.set_axes_limits(ax=ax)
return
示例2: MplPolygonalROI
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_zorder [as 别名]
class MplPolygonalROI(AbstractMplRoi):
"""
Defines and displays polygonal ROIs on matplotlib plots
Attributes:
plot_opts: Dictionary instance
A dictionary of plot keywords that are passed to
the patch representing the ROI. These control
the visual properties of the ROI
"""
def __init__(self, axes):
"""
:param axes: A matplotlib Axes object to attach the graphical ROI to
"""
AbstractMplRoi.__init__(self, axes)
self.plot_opts = {'edgecolor': PATCH_COLOR, 'facecolor': PATCH_COLOR,
'alpha': 0.3}
self._setup_patch()
def _setup_patch(self):
self._patch = Polygon(np.array(list(zip([0, 1], [0, 1]))))
self._patch.set_zorder(100)
self._patch.set(**self.plot_opts)
self._axes.add_patch(self._patch)
self._patch.set_visible(False)
self._sync_patch()
def _roi_factory(self):
return PolygonalROI()
def _sync_patch(self):
# Update geometry
if not self._roi.defined():
self._patch.set_visible(False)
else:
x, y = self._roi.to_polygon()
self._patch.set_xy(list(zip(x + [x[0]],
y + [y[0]])))
self._patch.set_visible(True)
# Update appearance
self._patch.set(**self.plot_opts)
# Refresh
self._axes.figure.canvas.draw()
def start_selection(self, event):
if event.inaxes != self._axes:
return False
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
elif not self._roi.contains(event.xdata, event.ydata):
return False
self._roi_store()
if event.key == SCRUBBING_KEY:
self._scrubbing = True
self._cx = event.xdata
self._cy = event.ydata
else:
self.reset()
self._roi.add_point(event.xdata, event.ydata)
self._mid_selection = True
self._sync_patch()
def update_selection(self, event):
if not self._mid_selection or event.inaxes != self._axes:
return False
if event.key == SCRUBBING_KEY:
if not self._roi.defined():
return False
if self._scrubbing:
self._roi.move_to(event.xdata - self._cx,
event.ydata - self._cy)
self._cx = event.xdata
self._cy = event.ydata
else:
self._roi.add_point(event.xdata, event.ydata)
self._sync_patch()
def finalize_selection(self, event):
self._scrubbing = False
self._mid_selection = False
self._patch.set_visible(False)
self._axes.figure.canvas.draw()
示例3: fillcontinentsX
# 需要导入模块: from matplotlib.patches import Polygon [as 别名]
# 或者: from matplotlib.patches.Polygon import set_zorder [as 别名]
def fillcontinentsX(self,color='0.8',lake_color=None,ax=None,zorder=None):
"""
Fill continents.
.. tabularcolumns:: |l|L|
============== ====================================================
Keyword Description
============== ====================================================
color color to fill continents (default gray).
lake_color color to fill inland lakes (default axes background).
ax axes instance (overrides default axes instance).
zorder sets the zorder for the continent polygons (if not
specified, uses default zorder for a Polygon patch).
Set to zero if you want to paint over the filled
continents).
============== ====================================================
After filling continents, lakes are re-filled with
axis background color.
returns a list of matplotlib.patches.Polygon objects.
"""
if self.resolution is None:
raise AttributeError, 'there are no boundary datasets associated with this Basemap instance'
# get current axes instance (if none specified).
ax = ax or self._check_ax()
# get axis background color.
axisbgc = ax.get_axis_bgcolor()
npoly = 0
polys = []
for x,y in self.coastpolygons:
xa = num.array(x,num.float32)
ya = num.array(y,num.float32)
# check to see if all four corners of domain in polygon (if so,
# don't draw since it will just fill in the whole map).
delx = 10; dely = 10
if self.projection in ['cyl']:
delx = 0.1
dely = 0.1
test1 = num.fabs(xa-self.urcrnrx) < delx
test2 = num.fabs(xa-self.llcrnrx) < delx
test3 = num.fabs(ya-self.urcrnry) < dely
test4 = num.fabs(ya-self.llcrnry) < dely
hasp1 = num.sum(test1*test3)
hasp2 = num.sum(test2*test3)
hasp4 = num.sum(test2*test4)
hasp3 = num.sum(test1*test4)
if not hasp1 or not hasp2 or not hasp3 or not hasp4:
xy = zip(xa.tolist(),ya.tolist())
if self.coastpolygontypes[npoly] not in [2,4]:
poly = Polygon(xy,facecolor=color,edgecolor=color,linewidth=0)
else: # lakes filled with background color by default
if lake_color is None:
poly = Polygon(xy,facecolor=axisbgc,edgecolor=axisbgc,linewidth=0)
else:
poly = Polygon(xy,facecolor=lake_color,edgecolor=lake_color,linewidth=0)
if zorder is not None:
poly.set_zorder(zorder)
ax.add_patch(poly)
polys.append(poly)
npoly = npoly + 1
# set axes limits to fit map region.
self.set_axes_limits(ax=ax)
return polys