本文整理汇总了Python中matplotlib.collections.PolyCollection.set_edgecolors方法的典型用法代码示例。如果您正苦于以下问题:Python PolyCollection.set_edgecolors方法的具体用法?Python PolyCollection.set_edgecolors怎么用?Python PolyCollection.set_edgecolors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PolyCollection
的用法示例。
在下文中一共展示了PolyCollection.set_edgecolors方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotcelldata
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_edgecolors [as 别名]
def plotcelldata(self, z, xlims=None, ylims=None, colorbar=True, **kwargs):
"""
Plot cell centered data
"""
ax=plt.gca()
fig = plt.gcf()
# Find the colorbar limits if unspecified
if self.clim is None:
self.clim = [z.min(),z.max()]
# Set the xy limits
if xlims is None or ylims is None:
xlims=self.xlims()
ylims=self.ylims()
collection = PolyCollection(self.xy(),closed=False,**kwargs)
collection.set_array(z)
collection.set_clim(vmin=self.clim[0],vmax=self.clim[1])
collection.set_edgecolors(collection.to_rgba(z))
ax.add_collection(collection)
ax.set_aspect('equal')
ax.set_xlim(xlims)
ax.set_ylim(ylims)
axcb=None
if colorbar:
axcb = fig.colorbar(collection)
return fig, ax, collection, axcb
示例2: VarPlot
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_edgecolors [as 别名]
class VarPlot(object):
def __init__(self, var, cmap, axes):
self.axes = axes
self.var = var
self.cmap = cmap
self.mesh = self.var.mesh
self.plot_mesh()
def plot_mesh(self):
vertexIDs = self.mesh._orderedCellVertexIDs
vertexCoords = self.mesh.vertexCoords
xCoords = numerix.take(vertexCoords[0], vertexIDs)
yCoords = numerix.take(vertexCoords[1], vertexIDs)
polys = []
for x, y in zip(xCoords.swapaxes(0, 1), yCoords.swapaxes(0, 1)):
polys.append(zip(x, y))
self.collection = PolyCollection(polys)
self.collection.set_linewidth(0.5)
self.axes.add_collection(self.collection)
self.update(self.var)
def update(self, var):
rgba = self.cmap(var.value)
self.collection.set_facecolors(rgba)
self.collection.set_edgecolors(rgba)
示例3: Matplotlib2DViewer
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_edgecolors [as 别名]
#.........这里部分代码省略.........
vars
a `CellVariable` object.
title
displayed at the top of the `Viewer` window
limits : dict
a (deprecated) alternative to limit keyword arguments
cmap
the colormap. Defaults to `matplotlib.cm.jet`
xmin, xmax, ymin, ymax, datamin, datamax
displayed range of data. Any limit set to
a (default) value of `None` will autoscale.
colorbar
plot a colorbar in specified orientation if not `None`
axes
if not `None`, `vars` will be plotted into this Matplotlib `Axes` object
"""
kwlimits.update(limits)
_MatplotlibViewer.__init__(self, vars=vars, title=title, figaspect=1. / 1.3,
cmap=cmap, colorbar=colorbar, axes=axes,
**kwlimits)
self.mesh = self.vars[0].getMesh()
vertexIDs = self.mesh._getOrderedCellVertexIDs()
vertexCoords = self.mesh.getVertexCoords()
xCoords = numerix.take(vertexCoords[0], vertexIDs)
yCoords = numerix.take(vertexCoords[1], vertexIDs)
polys = []
for x, y in zip(xCoords.swapaxes(0,1), yCoords.swapaxes(0,1)):
if hasattr(x, 'mask'):
x = x.compressed()
if hasattr(y, 'mask'):
y = y.compressed()
polys.append(zip(x,y))
import matplotlib
from matplotlib.collections import PolyCollection
self.collection = PolyCollection(polys)
self.collection.set_linewidth(0.5)
try:
self.axes.add_patch(self.collection)
except:
# PolyCollection not child of PatchCollection in matplotlib 0.98
self.axes.add_collection(self.collection)
xmin = self._getLimit('xmin', default=xCoords.min())
xmax = self._getLimit('xmax', default=xCoords.max())
ymin = self._getLimit('ymin', default=yCoords.min())
ymax = self._getLimit('ymax', default=yCoords.max())
self.axes.set_xlim(xmin=xmin, xmax=xmax)
self.axes.set_ylim(ymin=ymin, ymax=ymax)
self._plot()
def _getSuitableVars(self, vars):
from fipy.meshes.numMesh.mesh2D import Mesh2D
from fipy.variables.cellVariable import CellVariable
vars = [var for var in _MatplotlibViewer._getSuitableVars(self, vars) \
if ((isinstance(var.getMesh(), Mesh2D) and isinstance(var, CellVariable))
and var.getRank() == 0)]
if len(vars) == 0:
from fipy.viewers import MeshDimensionError
raise MeshDimensionError, "Matplotlib2DViewer can only display a rank-0, 2D CellVariable"
# this viewer can only display one variable
return [vars[0]]
def _plot(self):
## pylab.clf()
## ## Added garbage collection since matplotlib objects seem to hang
## ## around and accumulate.
## import gc
## gc.collect()
Z = self.vars[0].getValue()
zmin, zmax = self._autoscale(vars=self.vars,
datamin=self._getLimit(('datamin', 'zmin')),
datamax=self._getLimit(('datamax', 'zmax')))
diff = zmax - zmin
import matplotlib
if diff == 0:
rgba = self.cmap(0.5)
else:
rgba = self.cmap((Z - zmin) / diff)
self.collection.set_facecolors(rgba)
self.collection.set_edgecolors(rgba)
if self.colorbar is not None:
self.colorbar.plot(vmin=zmin, vmax=zmax)
示例4: Matplotlib2DViewer
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_edgecolors [as 别名]
#.........这里部分代码省略.........
fig = pylab.figure(self.id)
ax = fig.get_axes()[0]
from matplotlib.collections import PolyCollection
self.collection = PolyCollection(polys)
self.collection.set_linewidth(0.5)
try:
ax.add_patch(self.collection)
except:
# PolyCollection not child of PatchCollection in matplotlib 0.98
ax.add_collection(self.collection)
if self._getLimit('xmin') is None:
xmin = xCoords.min()
else:
xmin = self._getLimit('xmin')
if self._getLimit('xmax') is None:
xmax = xCoords.max()
else:
xmax = self._getLimit('xmax')
if self._getLimit('ymin') is None:
ymin = yCoords.min()
else:
ymin = self._getLimit('ymin')
if self._getLimit('ymax') is None:
ymax = yCoords.max()
else:
ymax = self._getLimit('ymax')
pylab.axis((xmin, xmax, ymin, ymax))
cbax, kw = matplotlib.colorbar.make_axes(ax, orientation='vertical')
# Set the colormap and norm to correspond to the data for which
# the colorbar will be used.
if cmap is None:
self.cmap = matplotlib.cm.jet
else:
self.cmap = cmap
norm = matplotlib.colors.normalize(vmin=-1, vmax=1)
# ColorbarBase derives from ScalarMappable and puts a colorbar
# in a specified axes, so it has everything needed for a
# standalone colorbar. There are many more kwargs, but the
# following gives a basic continuous colorbar with ticks
# and labels.
self.cb = matplotlib.colorbar.ColorbarBase(cbax, cmap=self.cmap,
norm=norm,
orientation='vertical')
self.cb.set_label(self.vars[0].name)
self._plot()
def _getSuitableVars(self, vars):
from fipy.meshes.numMesh.mesh2D import Mesh2D
from fipy.variables.cellVariable import CellVariable
vars = [var for var in _MatplotlibViewer._getSuitableVars(self, vars) \
if ((isinstance(var.getMesh(), Mesh2D) and isinstance(var, CellVariable))
and var.getRank() == 0)]
if len(vars) == 0:
from fipy.viewers import MeshDimensionError
raise MeshDimensionError, "Matplotlib2DViewer can only display a rank-0, 2D CellVariable"
# this viewer can only display one variable
return [vars[0]]
def _plot(self):
## pylab.clf()
## ## Added garbage collection since matplotlib objects seem to hang
## ## around and accumulate.
## import gc
## gc.collect()
Z = self.vars[0].getValue()
zmin, zmax = self._autoscale(vars=self.vars,
datamin=self._getLimit(('datamin', 'zmin')),
datamax=self._getLimit(('datamax', 'zmax')))
diff = zmax - zmin
import matplotlib
if diff == 0:
rgba = self.cmap(0.5)
else:
rgba = self.cmap((Z - zmin) / diff)
self.collection.set_facecolors(rgba)
self.collection.set_edgecolors(rgba)
self.cb.norm = matplotlib.colors.normalize(vmin=zmin, vmax=zmax)
self.cb.cmap = self.cmap
self.cb.draw_all()
示例5: Matplotlib2DViewer
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_edgecolors [as 别名]
#.........这里部分代码省略.........
def __init__(self, vars, title=None, limits={}, cmap=None, colorbar='vertical', axes=None, figaspect='auto', **kwlimits):
"""Creates a `Matplotlib2DViewer`.
:Parameters:
vars
a `CellVariable` object.
title
displayed at the top of the `Viewer` window
limits : dict
a (deprecated) alternative to limit keyword arguments
cmap
the colormap. Defaults to `matplotlib.cm.jet`
xmin, xmax, ymin, ymax, datamin, datamax
displayed range of data. Any limit set to
a (default) value of `None` will autoscale.
colorbar
plot a colorbar in specified orientation if not `None`
axes
if not `None`, `vars` will be plotted into this Matplotlib `Axes` object
figaspect
desired aspect ratio of figure. If arg is a number, use that aspect
ratio. If arg is 'auto', the aspect ratio will be determined from
the Variable's mesh.
"""
kwlimits.update(limits)
AbstractMatplotlib2DViewer.__init__(self, vars=vars, title=title, figaspect=figaspect,
cmap=cmap, colorbar=colorbar, axes=axes,
**kwlimits)
self.mesh = self.vars[0].mesh
vertexIDs = self.mesh._orderedCellVertexIDs
vertexCoords = self.mesh.vertexCoords
xCoords = numerix.take(vertexCoords[0], vertexIDs)
yCoords = numerix.take(vertexCoords[1], vertexIDs)
polys = []
for x, y in zip(xCoords.swapaxes(0, 1), yCoords.swapaxes(0, 1)):
if hasattr(x, 'mask'):
x = x.compressed()
if hasattr(y, 'mask'):
y = y.compressed()
polys.append(list(zip(x, y)))
from matplotlib.collections import PolyCollection
self.collection = PolyCollection(polys)
self.collection.set_linewidth(0.5)
try:
self.axes.add_patch(self.collection)
except:
# PolyCollection not child of PatchCollection in matplotlib 0.98
self.axes.add_collection(self.collection)
xmin = self._getLimit('xmin', default=xCoords.min())
xmax = self._getLimit('xmax', default=xCoords.max())
ymin = self._getLimit('ymin', default=yCoords.min())
ymax = self._getLimit('ymax', default=yCoords.max())
self.axes.set_xlim(xmin=xmin, xmax=xmax)
self.axes.set_ylim(ymin=ymin, ymax=ymax)
self._plot()
def _getSuitableVars(self, vars):
from fipy.meshes.mesh2D import Mesh2D
from fipy.variables.cellVariable import CellVariable
vars = [var for var in AbstractMatplotlib2DViewer._getSuitableVars(self, vars) \
if ((var.mesh.dim == 2 and isinstance(var, CellVariable))
and var.rank == 0)]
if len(vars) == 0:
from fipy.viewers import MeshDimensionError
raise MeshDimensionError("Matplotlib2DViewer can only display a rank-0, 2D CellVariable")
# this viewer can only display one variable
return [vars[0]]
def _plot(self):
## plt.clf()
## ## Added garbage collection since matplotlib objects seem to hang
## ## around and accumulate.
## import gc
## gc.collect()
Z = self.vars[0].value
self.norm.vmin = self._getLimit(('datamin', 'zmin'))
self.norm.vmax = self._getLimit(('datamax', 'zmax'))
rgba = self.cmap(self.norm(Z))
self.collection.set_facecolors(rgba)
self.collection.set_edgecolors(rgba)
if self.colorbar is not None:
self.colorbar.plot() #vmin=zmin, vmax=zmax)