本文整理汇总了Python中matplotlib.collections.PolyCollection.set_color方法的典型用法代码示例。如果您正苦于以下问题:Python PolyCollection.set_color方法的具体用法?Python PolyCollection.set_color怎么用?Python PolyCollection.set_color使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.collections.PolyCollection
的用法示例。
在下文中一共展示了PolyCollection.set_color方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: animate
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def animate(p):
global count, centers, angles, coords, skip, colors, histogram, success, angle_histogram
mc()
density = histogram/leny/dx/count
xnew, density = make_square(xcoords, density)
line.set_ydata(density)
ang_vals = angle_histogram/count/pi
ax3.collections = []
angplot = ax3.pcolormesh(x, theta, ang_vals, vmin=0, vmax=.01, edgecolors='face', cmap=cm.hot_r)
#angplot = ax3.contourf(x, theta, ang_vals, levels=arange(0, .0105, .001), extend="max", rasterized=True)
cbar_ax.collections = []
cs = fig.colorbar(angplot, cax=cbar_ax, ticks=[])
cs.cmap.set_over('k')
cs.set_clim([0, .01])
ax2.set_ylim(0, 0.8)
for i in xrange(n):
coords[i] = verts(centers[i], angles[i])
coll = PolyCollection(coords)
colors = zeros(n) + cdefault
colors[0] = cspecial
coll.set_color([cm.jet(val) for val in colors])
ax.collections=[]
ax.add_collection(coll)
ax.set_title("Attempted: %6i, Successful: %6i" %(count*n, success))
#fig.tight_layout()
print p
return line, ax2, ax3
示例2: set_data
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def set_data(self, zname, zdata, zcolor):
if zdata!=None:
if self.overall_plot_type=="polygon":
if zname not in self.clts: #plottables['plotted']:#self.pd.list_data():
clt=PolyCollection(zdata, alpha=0.5, antialiased=True)#, rasterized=False, antialiased=False)
clt.set_color(colorConverter.to_rgba(zcolor))
self.clts[zname]=clt
self.axe.add_collection(self.clts[zname], autolim=True)
else:
self.clts[zname].set_verts(zdata)
if self.overall_plot_type=="XY":
if zname not in self.clts:
clt = LineCollection(zdata)#, offsets=offs)
clt.set_color(colors)
#print dir(clt)
self.clts[zname]=clt
self.axe.add_collection(self.clts[zname], autolim=True)
self.axe.autoscale_view()
else:
self.clts[zname].set_segments(zdata)
if self.overall_plot_type=="img":
if zname not in self.clts:
axeimg=self.axe.imshow( Magvec,
vmin=amin(Magvec),
vmax=0.001, #amax(Magvec),
aspect="auto", origin="lower",
extent=[amin(yoko),amax(yoko), amin(freq),amax(freq)],
#cmap='RdBu'
)
self.fig.colorbar(axeimg)
示例3: set_data
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def set_data(self, zname, zdata, zcolor):
if zdata!=None:
if zname not in self.clts: #plottables['plotted']:#self.pd.list_data():
clt=PolyCollection(zdata, alpha=0.5, antialiased=True)#, rasterized=False, antialiased=False)
clt.set_color(colorConverter.to_rgba(zcolor))
self.clts[zname]=clt
self.axe.add_collection(self.clts[zname], autolim=True)
else:
self.clts[zname].set_verts(zdata)
示例4: poly_plot
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def poly_plot(self, zname, zdata, zcolor=None):
if zname not in self.clts:
clt=PolyCollection(zdata, alpha=0.5, antialiased=True)
if zcolor is not None:
clt.set_color(zcolor) #colorConverter.to_rgba(zcolor))
self.clts[zname]=clt
self.axe.add_collection(self.clts[zname])
else:
self.clts[zname].set_verts(zdata)
示例5: set_data
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def set_data(self, zname=None, zdata=None, zcolor=None, plot_type="poly"):
if zdata!=None:
if plot_type is "poly":
if zname not in self.clts: #plottables['plotted']:#self.pd.list_data():
clt=PolyCollection([], alpha=0.5, antialiased=True)#, rasterized=False, antialiased=False)
if zcolor is not None:
clt.set_color(colorConverter.to_rgba(zcolor))
self.clts[zname]=clt
self.axe.add_collection(self.clts[zname])
self.clts[zname].set_verts(zdata)
elif plot_type is "line":
if zname not in self.clts:
clt=LineCollection(zdata)#, linewidths=(0.5, 1, 1.5, 2),
#linestyles='solid', colors=("red", "blue", "green"))
if zcolor is not None:
clt.set_color(zcolor)
else:
clt.set_array(arange(len(zdata)))
else:
self.clts[zname].set_verts(zdata)
#self.set_xlim(x.min(), x.max())
#self.set_ylim(ys.min(), ys.max())
elif plot_type is "scatter":
self.axe.scatter(zdata, zdata)
elif plot_type is "colormap":
self.axe.pcolormesh(x, y, z)
if 0:
x = arange(3)
ys = array([x + i for i in arange(5)])
#xdata=arange(len(getattr(self, zname)))
data=[list(zip(x, y)) for y in ys]
line_segments = LineCollection(data,
linewidths=1,
linestyles='solid',
colors=mycolors)
print data
print len(data)
#print line_segments.properties()
#print line_segments.set_hatch("O")
#print dir(self.axe)
print [p.vertices for p in line_segments.get_paths()]#)
print line_segments.get_segments()
示例6: PolygonFormat
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [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)
示例7: __plot_variance
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def __plot_variance(self):
pointsMin = self.__calc_min()
pointsMax = self.__calc_max()
polys = []
variance = []
varMin = 1000
varMax = 0
lastX = None
lastYMin = None
lastYMax = None
for x in pointsMin.iterkeys():
if lastX is None:
lastX = x
if lastYMin is None:
lastYMin = pointsMin[x]
if lastYMax is None:
lastYMax = pointsMax[x]
polys.append([[x, pointsMin[x]],
[x, pointsMax[x]],
[lastX, lastYMax],
[lastX, lastYMin],
[x, pointsMin[x]]])
lastX = x
lastYMin = pointsMin[x]
lastYMax = pointsMax[x]
var = pointsMax[x] - pointsMin[x]
variance.append(var)
varMin = min(varMin, var)
varMax = max(varMax, var)
norm = Normalize(vmin=varMin, vmax=varMax)
sm = ScalarMappable(norm, self.colourMap)
colours = sm.to_rgba(variance)
pc = PolyCollection(polys)
pc.set_gid('plot')
pc.set_norm(norm)
pc.set_color(colours)
self.axes.add_collection(pc)
return None, None
示例8: min
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
depth = min(depth, slider1.valmax)
slider1.set_val(depth)
if (event.inaxes is playButt4):
for d in np.arange(-2, 2, .1):
depth = d
update(depth)
slider1.set_val(depth)
fig.canvas.mpl_connect('button_press_event', on_playButt)
# Back plane
verts3D = np.array([[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1],[-1,-1,1]])
vertsXY = [verts3D[:,:2]]
vertsZ = verts3D[:,2]
poly1 = PolyCollection(vertsXY)
poly1.set_alpha(0.2)
poly1.set_color('w')
poly1.set_edgecolor('k')
ax3d.add_collection3d(poly1, zs=vertsZ, zdir='y')
# Front plane
verts3D = np.array([[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,-1]])
vertsXY = [verts3D[:,:2]]
vertsZ = verts3D[:,2]
poly2 = PolyCollection(vertsXY)
poly2.set_alpha(0.5)
poly2.set_color('w')
poly2.set_edgecolor('k')
ax3d.add_collection3d(poly2, zs=vertsZ, zdir='y')
# Necker Radiobuttons
rax = plt.axes([0.005, 0.25, 0.16/winAspect, 0.4])
示例9: animate
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def animate(p):
global count, centers, angles, coords, extras, skip, colors, histogram, i, line2, success
if (i >= n):
i = 0
keep = True
ax.cla()
temp = move(centers[i])
tempa = turn(angles[i])
coords[n], coords2[n], extras[n], extras2[n] = chop(verts(temp, tempa))
xs = verts(temp, tempa)[:,0]
if max(xs) > lenx or min(xs) < 0:
keep = False
else:
for j in xrange(n):
if j != i and touch(temp, centers[j], tempa, angles[j]):
keep = False
break
count += 1
if keep:
success += 1
colors[n] = tempc
else:
colors[n] = badc
# for k in range(n+1):
# for j in range(len(extras[k,:])):
# lines = plot([extras[k,j-1,0], extras[k,j,0]], [extras[k,j-1,1], extras[k,j,1]], '--', color=colors[k], linewidth=2, alpha=alpha)
# lines = plot([extras2[k,j-1,0], extras2[k,j,0]], [extras2[k,j-1,1], extras2[k,j,1]], '--', color=colors[k], linewidth=2, alpha=alpha)
colors[i] = highlightc
# swap things around so the moving triangles are always on top
c = concatenate((coords, coords2), axis=0)
c_extra = concatenate((extras, extras2), axis=0)
cols = colors + colors
swap = c[-2]
swap_extra = c_extra[-2]
c[-2] = c[n]
c_extra[-2] = c_extra[n]
c[n] = swap
c_extra[n] = swap_extra
swap = cols[-2]
cols[-2] = cols[n]
cols[n] = swap
coll = PolyCollection(c)
coll.set_color(cols)
coll.set_alpha(alpha)
coll_extra = PolyCollection(c_extra)
coll_extra.set_color(cols)
coll_extra.set_alpha(.2)
#coll.set_color([cm.jet(x) for x in cols])
ax.collections=[]
ax.add_collection(coll_extra)
ax.add_collection(coll)
ax.set_title("Attempted moves: %i, Successful moves: %i" %(count, success))
ax.axhline(y=0, linestyle='--', linewidth=3, color='b', zorder=1)
ax.axhline(y=leny, linestyle='--', linewidth=3, color='orange', zorder=1)
ax.axvline(x=0, linestyle='-', color='k', linewidth=3, zorder=1)
ax.axvline(x=lenx, linestyle='-', color='k', linewidth=3, zorder=1)
arlen = .5
arwidth = .5
delta = periodic_diff(centers[i], temp)
for shift in [0, -leny, leny]:
if shift == 0:
aralpha = 1
else:
aralpha = .5
line2 = ax.arrow(centers[i,0], centers[i,1]+shift, delta[0],
delta[1], head_width=arwidth, head_length=arlen,
linewidth=2, facecolor='slategray', zorder=3, alpha=aralpha)
fig.tight_layout()
if keep:
centers[i] = temp
angles[i] = tempa
coords[i], coords2[i], extras[i], extras2[i] = chop(verts(centers[i], angles[i]))
colors[i] = goodc
else:
colors[i] = rejectc
if (i == n-1):
colors = [defaultc]*(n+1)
i += 1
return ax, line2
示例10: plot_volume
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
def plot_volume(sim, vol=None, center=None, size=None,
options=None, plot3D=False, label=None):
options = options if options else def_plot_options
fig=plt.gcf()
ax=fig.gca(projection='3d') if plot3D else fig.gca()
if vol:
center, size = vol.center, vol.size
v0=np.array([center.x, center.y])
dx,dy=np.array([0.5*size.x,0.0]), np.array([0.0,0.5*size.y])
if plot3D:
zmin,zmax = ax.get_zlim3d()
z0 = zmin + options['zrel']*(zmax-zmin)
##################################################
# add polygon(s) to the plot to represent the volume
##################################################
def add_to_plot(c):
ax.add_collection3d(c,zs=z0,zdir='z') if plot3D else ax.add_collection(c)
if size.x==0.0 or size.y==0.0: # zero thickness, plot as line
polygon = [ v0+dx+dy, v0-dx-dy ]
add_to_plot( LineCollection( [polygon], colors=options['line_color'],
linewidths=options['line_width'],
linestyles=options['line_style']
)
)
else:
if options['fill_color'] != 'none': # first copy: faces, no edges
polygon = np.array([v0+dx+dy, v0-dx+dy, v0-dx-dy, v0+dx-dy])
pc=PolyCollection( [polygon], linewidths=0.0)
pc.set_color(options['fill_color'])
pc.set_alpha(options['alpha'])
add_to_plot(pc)
if options['boundary_width']>0.0: # second copy: edges, no faces
closed_polygon = np.array([v0+dx+dy, v0-dx+dy, v0-dx-dy, v0+dx-dy, v0+dx+dy])
lc=LineCollection([closed_polygon])
lc.set_linestyle(options['boundary_style'])
lc.set_linewidth(options['boundary_width'])
lc.set_edgecolor(options['boundary_color'])
add_to_plot(lc)
######################################################################
# attempt to autodetermine text rotation and alignment
######################################################################
if label:
x0, y0, r, h, v = np.mean(ax.get_xlim()),np.mean(ax.get_ylim()), 0, 'center', 'center'
if size.y==0.0:
v = 'bottom' if center.y>y0 else 'top'
elif size.x==0.0:
r, h = (270,'left') if center.x>x0 else (90,'right')
if plot3D:
ax.text(center.x, center.y, z0, label, rotation=r,
fontsize=options['fontsize'], color=options['line_color'],
horizontalalignment=h, verticalalignment=v)
else:
ax.text(center.x, center.y, label, rotation=r,
fontsize=options['fontsize'], color=options['line_color'],
horizontalalignment=h, verticalalignment=v)
示例11: QuiverKey
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
class QuiverKey(Artist):
''' Labelled arrow for use as a quiver plot scale key.
'''
halign = {'N': 'center', 'S': 'center', 'E': 'left', 'W': 'right'}
valign = {'N': 'bottom', 'S': 'top', 'E': 'center', 'W': 'center'}
pivot = {'N': 'mid', 'S': 'mid', 'E': 'tip', 'W': 'tail'}
def __init__(self, Q, X, Y, U, label, **kw):
Artist.__init__(self)
self.Q = Q
self.X = X
self.Y = Y
self.U = U
self.coord = kw.pop('coordinates', 'axes')
self.color = kw.pop('color', None)
self.label = label
self.labelsep = T.Value(kw.pop('labelsep', 0.1)) * Q.ax.figure.dpi
self.labelpos = kw.pop('labelpos', 'N')
self.labelcolor = kw.pop('labelcolor', None)
self.fontproperties = kw.pop('fontproperties', dict())
self.kw = kw
self.text = Text(text=label,
horizontalalignment=self.halign[self.labelpos],
verticalalignment=self.valign[self.labelpos],
fontproperties=FontProperties(**self.fontproperties))
if self.labelcolor is not None:
self.text.set_color(self.labelcolor)
self._initialized = False
self.zorder = Q.zorder + 0.1
__init__.__doc__ = _quiverkey_doc
def _init(self):
if not self._initialized:
self._set_transform()
_pivot = self.Q.pivot
self.Q.pivot = self.pivot[self.labelpos]
self.verts = self.Q._make_verts(nx.array([self.U]), nx.zeros((1,)))
self.Q.pivot = _pivot
kw = self.Q.polykw
kw.update(self.kw)
self.vector = PolyCollection(self.verts,
offsets=[(self.X,self.Y)],
transOffset=self.get_transform(),
**kw)
if self.color is not None:
self.vector.set_color(self.color)
self.vector.set_transform(self.Q.get_transform())
self._initialized = True
def _text_x(self, x):
if self.labelpos == 'E':
return x + self.labelsep.get()
elif self.labelpos == 'W':
return x - self.labelsep.get()
else:
return x
def _text_y(self, y):
if self.labelpos == 'N':
return y + self.labelsep.get()
elif self.labelpos == 'S':
return y - self.labelsep.get()
else:
return y
def draw(self, renderer):
self._init()
self.vector.draw(renderer)
x, y = self.get_transform().xy_tup((self.X, self.Y))
self.text.set_x(self._text_x(x))
self.text.set_y(self._text_y(y))
self.text.draw(renderer)
def _set_transform(self):
if self.coord == 'data':
self.set_transform(self.Q.ax.transData)
elif self.coord == 'axes':
self.set_transform(self.Q.ax.transAxes)
elif self.coord == 'figure':
self.set_transform(self.Q.ax.figure.transFigure)
elif self.coord == 'inches':
dx = ax.figure.dpi
bb = T.Bbox(T.origin(), T.Point(dx, dx))
trans = T.get_bbox_transform(T.unit_bbox(), bb)
self.set_transform(trans)
else:
raise ValueError('unrecognized coordinates')
quiverkey_doc = _quiverkey_doc
示例12: range
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
species_idx = 0
plt_range = numpy.arange(0, 800, 1)
fig = plt.figure(1)
data_TL = []
data_G = []
for result_idx in range(len(tl_args_list)):
density_TL = stats.gaussian_kde(tl_results[result_idx][species_idx][1])
density_G = stats.gaussian_kde(g_results[result_idx][species_idx][1])
data_TL.append(list(zip(plt_range, density_TL(plt_range))))
data_G.append(list(zip(plt_range, density_G(plt_range))))
poly_TL = PolyCollection(data_TL)
poly_TL.set_alpha(0.5)
poly_TL.set_color('red')
poly_G = PolyCollection(data_G)
poly_G.set_alpha(0.5)
poly_G.set_color('blue')
ax = fig.gca(projection='3d')
ax.set_xlabel('species_0')
# ax.set_ylabel('time')
ax.set_xlim3d(0, 800)
ax.set_ylim3d(0, 7)
ax.set_zlabel('proportion')
ax.set_zlim3d(0, 0.015)
ax.add_collection3d(poly_TL, zs=numpy.arange(1, 10, 1), zdir='y')
ax.add_collection3d(poly_G, zs=numpy.arange(1, 10, 1), zdir='y')
示例13: PolyCollection
# 需要导入模块: from matplotlib.collections import PolyCollection [as 别名]
# 或者: from matplotlib.collections.PolyCollection import set_color [as 别名]
ax.set_xlabel('X')
ax.set_ylabel('Z') # swap Y and Z
ax.set_zlabel('Y')
ax.set_xlim3d(-1, 1)
ax.set_ylim3d(-1, 1)
ax.set_zlim3d(-1, 1)
#### Polygon1 ####
# 2D [[x,y]...] and 1D [z...]
verts1 = [[[-1,-1], [1., -1], [1., 1.], [-1, 1.], [-1,-1]]]
poly1 = PolyCollection(verts1)
poly1.set_alpha(0.7)
poly1.set_color('r')
zs=[-1,-1,1,1,-1]
ax.add_collection3d(poly1, zs=zs, zdir='y')
#### Polygon2 ####
# 3D [[x,y,z]...] list
verts3D = np.array([[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0],[-1,-1,0]])
# Split 3D [[x,y,z]...] list into 2D [[x,y]...] and 1D [z...]
vertsXY = [[[verts3D[i][0], verts3D[i][1]] for i in range(len(verts3D))]]
vertsZ = [ verts3D[i][2] for i in range(len(verts3D))]
poly2 = PolyCollection(vertsXY)
poly2.set_alpha(0.7)
poly2.set_color('g')
ax.add_collection3d(poly2, zs=vertsZ, zdir='y')