本文整理汇总了Python中matplotlib.collections.PolyCollection.set_verts方法的典型用法代码示例。如果您正苦于以下问题:Python PolyCollection.set_verts方法的具体用法?Python PolyCollection.set_verts怎么用?Python PolyCollection.set_verts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PolyCollection
的用法示例。
在下文中一共展示了PolyCollection.set_verts方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_3d_projection
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def do_3d_projection(self, renderer):
"""
Perform the 3D projection for this object.
"""
# FIXME: This may no longer be needed?
if self._A is not None:
self.update_scalarmappable()
self._facecolors3d = self._facecolors
txs, tys, tzs = proj3d.proj_transform_vec(self._vec, renderer.M)
xyzlist = [(txs[si:ei], tys[si:ei], tzs[si:ei])
for si, ei in self._segis]
# This extra fuss is to re-order face / edge colors
cface = self._facecolors3d
cedge = self._edgecolors3d
if len(cface) != len(xyzlist):
cface = cface.repeat(len(xyzlist), axis=0)
if len(cedge) != len(xyzlist):
if len(cedge) == 0:
cedge = cface
else:
cedge = cedge.repeat(len(xyzlist), axis=0)
# if required sort by depth (furthest drawn first)
if self._zsort:
z_segments_2d = sorted(
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
for idx, ((xs, ys, zs), fc, ec)
in enumerate(zip(xyzlist, cface, cedge))),
key=lambda x: x[0], reverse=True)
else:
raise ValueError("whoops")
segments_2d = [s for z, s, fc, ec, idx in z_segments_2d]
if self._codes3d is not None:
codes = [self._codes3d[idx] for z, s, fc, ec, idx in z_segments_2d]
PolyCollection.set_verts_and_codes(self, segments_2d, codes)
else:
PolyCollection.set_verts(self, segments_2d, self._closed)
self._facecolors2d = [fc for z, s, fc, ec, idx in z_segments_2d]
if len(self._edgecolors3d) == len(cface):
self._edgecolors2d = [ec for z, s, fc, ec, idx in z_segments_2d]
else:
self._edgecolors2d = self._edgecolors3d
# Return zorder value
if self._sort_zpos is not None:
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
return ztrans[2][0]
elif tzs.size > 0 :
# FIXME: Some results still don't look quite right.
# In particular, examine contourf3d_demo2.py
# with az = -54 and elev = -45.
return np.min(tzs)
else :
return np.nan
示例2: do_3d_projection
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def do_3d_projection(self, renderer):
'''
Perform the 3D projection for this object.
'''
# FIXME: This may no longer be needed?
if self._A is not None:
self.update_scalarmappable()
self._facecolors3d = self._facecolors
txs, tys, tzs = proj3d.proj_transform_vec(self._vec, renderer.M)
xyzlist = [(txs[si:ei], tys[si:ei], tzs[si:ei]) \
for si, ei in self._segis]
# This extra fuss is to re-order face / edge colors
cface = self._facecolors3d
cedge = self._edgecolors3d
if len(cface) != len(xyzlist):
cface = cface.repeat(len(xyzlist), axis=0)
if len(cedge) != len(xyzlist):
if len(cedge) == 0:
cedge = cface
cedge = cedge.repeat(len(xyzlist), axis=0)
# if required sort by depth (furthest drawn first)
if self._zsort:
z_segments_2d = [(self._zsortfunc(zs), zip(xs, ys), fc, ec) for
(xs, ys, zs), fc, ec in zip(xyzlist, cface, cedge)]
z_segments_2d.sort(cmp=lambda x, y: cmp(y[0], x[0]))
else:
raise ValueError, "whoops"
segments_2d = [s for z, s, fc, ec in z_segments_2d]
PolyCollection.set_verts(self, segments_2d)
self._facecolors2d = [fc for z, s, fc, ec in z_segments_2d]
if len(self._edgecolors3d) == len(cface):
self._edgecolors2d = [ec for z, s, fc, ec in z_segments_2d]
else:
self._edgecolors2d = self._edgecolors3d
# Return zorder value
if self._sort_zpos is not None:
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
return ztrans[2][0]
elif tzs.size > 0 :
# FIXME: Some results still don't look quite right.
# In particular, examine contourf3d_demo2.py
# with az = -54 and elev = -45.
return np.min(tzs)
else :
return np.nan
示例3: ScatterPlotCC
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
class ScatterPlotCC(ScatterPlot):
def get_polygon(self, x, y, c):
color_map = ('c', 'r', 'b', 'm', 'y', 'g')
d = defaultdict(list)
for p, cc in zip(zip(x, y), c):
d[cc].append(p)
polygons = []
colors = []
for k in set(c):
if len(d[k]) == 2:
pt1 = d[k][0]
pt2 = d[k][1]
dist = math.sqrt((pt1[0] - pt2[0]) ** 2 + (pt1[1] - pt2[1]) ** 2)
xmid = (pt1[0] + pt2[0]) / 2
ymid = (pt1[1] + pt2[1]) / 2
polygons.append(d[k])
colors.append(color_map[k])
elif len(d[k]) == 1:
pass
else:
ch = ConvexHull(d[k])
points = ch.points
pts = zip(points[ch.vertices, 0], points[ch.vertices, 1])
polygons.append(pts)
colors.append(color_map[k])
return polygons, colors
def setup_plot(self):
ax = plt.gca()
x, y, c = next(self.stream)
po, co = self.get_polygon(x, y, c)
self.poly = PolyCollection(po, facecolors = co, edgecolors='none')
ax.add_collection(self.poly)
self.scat = ax.scatter(x, y, c='k', marker = self.marker, s = 25)
return self.scat
def update_plot(self):
x, y, c = next(self.stream)
new_data = np.array(zip(x, y))
po, co = self.get_polygon(x, y, c)
self.poly.set_facecolor(co)
self.poly.set_verts(po)
self.scat.set_offsets(new_data)
return self.scat
示例4: do_3d_projection
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def do_3d_projection(self, renderer):
'''
Perform the 3D projection for this object.
'''
if self._A is not None:
self.update_scalarmappable()
self._facecolors3d = self._facecolors
txs, tys, tzs = proj3d.proj_transform_vec(self._vec, renderer.M)
xyzlist = [(txs[si:ei], tys[si:ei], tzs[si:ei]) \
for si, ei in self._segis]
# This extra fuss is to re-order face / edge colors
cface = self._facecolors3d
cedge = self._edgecolors3d
if len(cface) != len(xyzlist):
cface = cface.repeat(len(xyzlist), axis=0)
if len(cedge) != len(xyzlist):
if len(cedge) == 0:
cedge = cface
cedge = cedge.repeat(len(xyzlist), axis=0)
# if required sort by depth (furthest drawn first)
if self._zsort:
z_segments_2d = [(self._zsortfunc(zs), zip(xs, ys), fc, ec) for
(xs, ys, zs), fc, ec in zip(xyzlist, cface, cedge)]
z_segments_2d.sort(key=lambda x: x[0], reverse=True)
else:
raise ValueError, "whoops"
segments_2d = [s for z, s, fc, ec in z_segments_2d]
PolyCollection.set_verts(self, segments_2d)
self._facecolors2d = [fc for z, s, fc, ec in z_segments_2d]
if len(self._edgecolors3d) == len(cface):
self._edgecolors2d = [ec for z, s, fc, ec in z_segments_2d]
else:
self._edgecolors2d = self._edgecolors3d
# Return zorder value
if self._sort_zpos is not None:
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
return ztrans[2][0]
else:
return np.min(tzs)
示例5: PolygonFormat
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
class PolygonFormat(LineFormat):
clt=Typed(PolyCollection)
antialiased=Bool(True)
def polygon_plot(self, *args, **kwargs):
kwargs=process_kwargs(self, kwargs)
#self.xdata=[arg[0] for arg in args[0][0]]
#self.zdata=[[vert[1] for vert in line] for line in args[0]]
self.clt=PolyCollection(args[0], alpha=self.alpha, antialiased=self.antialiased)
self.clt.set_color(self.color) #from matplotlib.colors import colorConverter colorConverter.to_rgba(
self.plotter.axes.add_collection(self.clt)
def alter_xy(self, *args, **kwargs):
self.color=kwargs.pop("color", self.color)
zdata=args[0]
self.clt.set_verts(zdata)
self.clt.set_color(self.color)
示例6: do_3d_projection
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def do_3d_projection(self, renderer):
'''
Perform the 3D projection for this object.
'''
if self._A is not None:
self.update_scalarmappable()
self._facecolors3d = self._facecolors
txs, tys, tzs = proj3d.proj_transform_vec(self._vec, renderer.M)
xyzlist = [(txs[si:ei], tys[si:ei], tzs[si:ei]) \
for si, ei in self._segis]
cface = self._facecolors3d
cedge = self._edgecolors3d
if len(cface) != len(xyzlist):
cface = cface.repeat(len(xyzlist), axis=0)
if len(cedge) != len(xyzlist):
if len(cedge) == 0:
cedge = cface
cedge = cedge.repeat(len(xyzlist), axis=0)
if self._zsort:
z_segments_2d = [(np.average(zs), zip(xs, ys), fc, ec) for
(xs, ys, zs), fc, ec in zip(xyzlist, cface, cedge)]
z_segments_2d.sort(cmp=lambda x, y: cmp(y[0], x[0]))
else:
raise ValueError, "whoops"
segments_2d = [s for z, s, fc, ec in z_segments_2d]
PolyCollection.set_verts(self, segments_2d)
self._facecolors2d = [fc for z, s, fc, ec in z_segments_2d]
if len(self._edgecolors3d) == len(cface):
self._edgecolors2d = [ec for z, s, fc, ec in z_segments_2d]
else:
self._edgecolors2d = self._edgecolors3d
if self._sort_zpos is not None:
zvec = np.array([[0], [0], [self._sort_zpos], [1]])
ztrans = proj3d.proj_transform_vec(zvec, renderer.M)
return ztrans[2][0]
else:
return np.min(tzs)
示例7: set_verts
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def set_verts(self, verts, closed=True):
'''Set 3D vertices.'''
self.get_vector(verts)
# 2D verts will be updated at draw time
PolyCollection.set_verts(self, [], closed)
示例8: set_verts
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
def set_verts(self, verts, closed=True):
"""Set 3D vertices."""
self.get_vector(verts)
# 2D verts will be updated at draw time
PolyCollection.set_verts(self, [], False)
self._closed = closed
示例9: Animator
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_verts [as 别名]
#.........这里部分代码省略.........
#remove text labels
#for i in range(len(collision)):
# text_labels[i].remove()
#add polygon objects
def add_polygon_objects(self,verts,collision):
poly_colors = self.generate_color_array(collision)
self.polygons = PolyCollection(verts, facecolors=poly_colors)
self.ax.add_collection(self.polygons)
#add text label
num_circles = self.circles.get_offsets().shape[1]
text_labels = [None] * len(collision)
for i in range(len(collision)):
temp = np.array(verts[i])
x = np.mean(temp[:,0])
y = np.mean(temp[:,1])
text_labels[i]= plt.text(x,y,str(i+num_circles),color = 'w')
self.polygon_labels = text_labels
plt.draw()
plt.pause(0.1)
#remove text labels
#for i in range(len(collision)):
# text_labels[i].remove()
#remove circular objects:
def remove_circles(self):
self.circles.remove()
for label in self.circle_labels:
label.remove()
#remove polygon objects:
def remove_polygons(self):
self.polygons.remove()
for label in self.polygon_labels:
label.remove()
#update circular objects
def update_circular_objects(self,positions,collision):
#set circle colors
circ_colors = self.generate_color_array(collision)
self.circles.set_facecolors(circ_colors)
#set circle positions
self.circles.set_offsets(positions)
#remove labels
for label in self.circle_labels:
label.remove()
#add labels
text_labels = [None] * len(collision)
for i in range(len(collision)):
text_labels[i]= plt.text(positions[i,0],positions[i,1],str(i),color = 'w')
self.circle_labels = text_labels
plt.draw()
plt.pause(0.1)
#update polygon objects
def update_polygon_objects(self,positions,collision):
#set polygon colors
poly_colors = self.generate_color_array(collision)
self.polygons.set_facecolors(poly_colors)
#set polygon positions
#print 'new verts positions=' , positions
self.polygons.set_verts(positions)
#remove labels
for label in self.polygon_labels:
label.remove()
#add new labels
num_circles = self.circles.get_offsets().shape[1]
#print self.polygons.get_offsets()
#assert(0)
text_labels = [None] * len(collision)
for i in range(len(collision)):
temp = np.array(positions[i])
x = np.mean(temp[:,0])
y = np.mean(temp[:,1])
text_labels[i]= plt.text(x,y,str(i+num_circles),color = 'w')
self.polygon_labels = text_labels
plt.draw()
plt.pause(0.1)