本文整理匯總了Python中matplotlib.path方法的典型用法代碼示例。如果您正苦於以下問題:Python matplotlib.path方法的具體用法?Python matplotlib.path怎麽用?Python matplotlib.path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類matplotlib
的用法示例。
在下文中一共展示了matplotlib.path方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _paint_path
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def _paint_path(closep, fillp, strokep):
"""Return the PDF operator to paint a path in the following way:
closep: close the path before painting
fillp: fill the path with the fill color
strokep: stroke the outline of the path with the line color"""
if strokep:
if closep:
if fillp:
return Op.close_fill_stroke
else:
return Op.close_stroke
else:
if fillp:
return Op.fill_stroke
else:
return Op.stroke
else:
if fillp:
return Op.fill
else:
return Op.endpath
示例2: writePathCollectionTemplates
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def writePathCollectionTemplates(self):
for (name, path, trans, ob, joinstyle, capstyle, padding, filled,
stroked) in self.paths:
pathops = self.pathOperations(path, trans, simplify=False)
bbox = path.get_extents(trans)
if not np.all(np.isfinite(bbox.extents)):
extents = [0, 0, 0, 0]
else:
bbox = bbox.padded(padding)
extents = list(bbox.extents)
self.beginStream(
ob.id, None,
{'Type': Name('XObject'), 'Subtype': Name('Form'),
'BBox': extents})
self.output(GraphicsContextPdf.joinstyles[joinstyle], Op.setlinejoin)
self.output(GraphicsContextPdf.capstyles[capstyle], Op.setlinecap)
self.output(*pathops)
self.output(Op.paint_path(False, filled, stroked))
self.endStream()
示例3: clip_cmd
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def clip_cmd(self, cliprect, clippath):
"""Set clip rectangle. Calls self.pop() and self.push()."""
cmds = []
# Pop graphics state until we hit the right one or the stack is empty
while ((self._cliprect, self._clippath) != (cliprect, clippath)
and self.parent is not None):
cmds.extend(self.pop())
# Unless we hit the right one, set the clip polygon
if ((self._cliprect, self._clippath) != (cliprect, clippath) or
self.parent is None):
cmds.extend(self.push())
if self._cliprect != cliprect:
cmds.extend([cliprect, Op.rectangle, Op.clip, Op.endpath])
if self._clippath != clippath:
path, affine = clippath.get_transformed_path_and_affine()
cmds.extend(
PdfFile.pathOperations(path, affine, simplify=False) +
[Op.clip, Op.endpath])
return cmds
示例4: _load_bitmap
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def _load_bitmap(filename):
"""
Load a bitmap file from the backends/images subdirectory in which the
matplotlib library is installed. The filename parameter should not
contain any path information as this is determined automatically.
Returns a wx.Bitmap object
"""
basedir = os.path.join(rcParams['datapath'],'images')
bmpFilename = os.path.normpath(os.path.join(basedir, filename))
if not os.path.exists(bmpFilename):
raise IOError('Could not find bitmap file "%s"; dying'%bmpFilename)
bmp = wx.Bitmap(bmpFilename)
return bmp
示例5: draw_path_collection
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def draw_path_collection(self, gc, master_transform, paths, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds, urls,
offset_position):
if offset_position=='data':
offset_position = True
else:
offset_position = False
path_ids = []
for path, transform in self._iter_collection_raw_paths(
master_transform, paths, all_transforms):
path_ids.append((path, transform))
master_transform = master_transform.get_matrix()
all_transforms = [t.get_matrix() for t in all_transforms]
offsetTrans = offsetTrans.get_matrix()
gc.draw_path_collection(master_transform, path_ids, all_transforms,
offsets, offsetTrans, facecolors, edgecolors,
linewidths, linestyles, antialiaseds,
offset_position)
示例6: linear_spine
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def linear_spine(cls, axes, spine_type, **kwargs):
"""
(staticmethod) Returns a linear :class:`Spine`.
"""
# all values of 13 get replaced upon call to set_bounds()
if spine_type == 'left':
path = mpath.Path([(0.0, 13), (0.0, 13)])
elif spine_type == 'right':
path = mpath.Path([(1.0, 13), (1.0, 13)])
elif spine_type == 'bottom':
path = mpath.Path([(13, 0.0), (13, 0.0)])
elif spine_type == 'top':
path = mpath.Path([(13, 1.0), (13, 1.0)])
else:
raise ValueError('unable to make path for spine "%s"' % spine_type)
result = cls(axes, spine_type, path, **kwargs)
return result
示例7: _load_bitmap
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def _load_bitmap(filename):
"""
Load a bitmap file from the backends/images subdirectory in which the
matplotlib library is installed. The filename parameter should not
contain any path information as this is determined automatically.
Returns a wx.Bitmap object
"""
basedir = os.path.join(rcParams['datapath'], 'images')
bmpFilename = os.path.normpath(os.path.join(basedir, filename))
if not os.path.exists(bmpFilename):
raise IOError('Could not find bitmap file "%s"; dying' % bmpFilename)
bmp = wx.Bitmap(bmpFilename)
return bmp
示例8: linear_spine
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def linear_spine(cls, axes, spine_type, **kwargs):
"""
(staticmethod) Returns a linear :class:`Spine`.
"""
# all values of 0.999 get replaced upon call to set_bounds()
if spine_type == 'left':
path = mpath.Path([(0.0, 0.999), (0.0, 0.999)])
elif spine_type == 'right':
path = mpath.Path([(1.0, 0.999), (1.0, 0.999)])
elif spine_type == 'bottom':
path = mpath.Path([(0.999, 0.0), (0.999, 0.0)])
elif spine_type == 'top':
path = mpath.Path([(0.999, 1.0), (0.999, 1.0)])
else:
raise ValueError('unable to make path for spine "%s"' % spine_type)
result = cls(axes, spine_type, path, **kwargs)
result.set_visible(rcParams['axes.spines.{0}'.format(spine_type)])
return result
示例9: DrawContourAndMark
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def DrawContourAndMark(contour, x, y, z, level, clipborder, patch, m):
# 是否繪製等值線 ------ 等值線和標注是一體的
if contour.contour['visible']:
matplotlib.rcParams['contour.negative_linestyle'] = 'dashed'
if contour.contour['colorline']:
CS1 = m.contour(x, y, z, levels=level, linewidths=contour.contour['linewidth'])
else:
CS1 = m.contour(x,
y,
z,
levels=level,
linewidths=contour.contour['linewidth'],
colors=contour.contour['linecolor'])
# 是否繪製等值線標注
CS2 = None
if contour.contourlabel['visible']:
CS2 = plt.clabel(CS1,
inline=1,
fmt=contour.contourlabel['fmt'],
inline_spacing=contour.contourlabel['inlinespacing'],
fontsize=contour.contourlabel['fontsize'],
colors=contour.contourlabel['fontcolor'])
# 用區域邊界裁切等值線圖
if clipborder.path is not None and clipborder.using:
for collection in CS1.collections:
# collection.set_clip_on(True)
collection.set_clip_path(patch)
if CS2 is not None:
for text in CS2:
if not clipborder.path.contains_point(text.get_position()):
text.remove()
示例10: DrawClipBorders
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def DrawClipBorders(clipborders):
# 繪製裁切區域邊界並返回
path = clipborders[0].path
linewidth = clipborders[0].linewidth
linecolor = clipborders[0].linecolor
if path is not None:
patch = patches.PathPatch(path, linewidth=linewidth, facecolor='none', edgecolor=linecolor)
plt.gca().add_patch(patch)
else:
patch = None
return patch
示例11: DrawBorders
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def DrawBorders(m, products):
"""
畫縣市邊界
:param m: 畫布對象(plt或投影後的plt)
:param products: 產品參數
:return:
"""
try:
for area in products.map.borders:
if not area.draw:
continue
if area.filetype == 'SHP': # shp文件
if m is plt:
# Map.DrawShapeFile(area)
Map.readshapefile(area.file.replace('.shp', ''),
os.path.basename(area.file),
color=area.linecolor,
linewidth=area.linewidth)
else:
m.readshapefile(area.file.replace('.shp', ''),
os.path.basename(area.file),
color=area.linecolor)
else: # 文本文件 , 畫之前 路徑中的點已經被投影了
if area.path is None:
continue
if area.polygon == 'ON':
area_patch = patches.PathPatch(area.path,
linewidth=area.linewidth,
linestyle='solid',
facecolor='none',
edgecolor=area.linecolor)
plt.gca().add_patch(area_patch)
else:
x, y = list(zip(*area.path.vertices))
m.plot(x, y, 'k-', linewidth=area.linewidth, color=area.linecolor)
except Exception as err:
print(u'【{0}】{1}-{2}'.format(products.xmlfile, err, datetime.now()))
示例12: DrawShapeFile
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def DrawShapeFile(area):
"""
在畫布上繪製shp文件
:param area: 包含shp文件名及線寬和線顏色的一個字典
:return:
"""
try:
shpfile = area.file
border_shape = shapefile.Reader(shpfile)
border = border_shape.shapes()
for b in border:
border_points = b.points
path_data = []
count = 0
for cell in border_points:
if count == 0:
trans = (Path.MOVETO, (cell[0], cell[1]))
path_data += [trans]
cell_end = cell
else:
trans = (Path.CURVE4, (cell[0], cell[1]))
path_data += [trans]
trans = (Path.CLOSEPOLY, (cell_end[0], cell_end[1]))
path_data += [trans]
codes, verts = list(zip(*path_data))
path = Path(verts, codes)
x, y = list(zip(*path.vertices))
plt.plot(x, y, 'k-', linewidth=area.linewidth, color=area.linecolor)
except Exception as err:
print(u'【{0}】{1}-{2}'.format(area['file'], err, datetime.now()))
示例13: GetFontProperties
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def GetFontProperties(font):
fontfile = r"C:\WINDOWS\Fonts\{0}".format(font['family'])
if not os.path.exists(fontfile):
fp = FontProperties(family=font['family'], weight=font['weight'], size=font['size'])
else:
fp = FontProperties(fname=fontfile, weight=font['weight'], size=font['size'])
return fp
示例14: _ring_coding
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def _ring_coding(ob):
# The codes will be all "LINETO" commands, except for "MOVETO"s at the
# beginning of each subpath
n = len(ob.coords)
codes = np.ones(n, dtype=matplotlib.path.Path.code_type) * \
matplotlib.path.Path.LINETO
codes[0] = matplotlib.path.Path.MOVETO
return codes
###############################################################################
# https://sgillies.net/2010/04/06/painting-punctured-polygons-with-matplotlib.html
示例15: _pathify
# 需要導入模塊: import matplotlib [as 別名]
# 或者: from matplotlib import path [as 別名]
def _pathify(polygon):
# Convert coordinates to path vertices. Objects produced by Shapely's
# analytic methods have the proper coordinate order, no need to sort.
vertices = np.concatenate(
[np.asarray(polygon.exterior)]
+ [np.asarray(r) for r in polygon.interiors])
codes = np.concatenate(
[_ring_coding(polygon.exterior)]
+ [_ring_coding(r) for r in polygon.interiors])
return matplotlib.path.Path(vertices, codes)
###############################################################################
###############################################################################