本文整理汇总了Python中matplotlib.patches.Ellipse.set_facecolor方法的典型用法代码示例。如果您正苦于以下问题:Python Ellipse.set_facecolor方法的具体用法?Python Ellipse.set_facecolor怎么用?Python Ellipse.set_facecolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Ellipse
的用法示例。
在下文中一共展示了Ellipse.set_facecolor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_qudratic_confidence_region_2D_ellipsoid
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plot_qudratic_confidence_region_2D_ellipsoid( \
config, center, ellipsoid, no_grid, rows, cols, fig):
subell = ellipsoid[numpy.ix_([rows,cols],[rows,cols])]
eigenvals, eigenvecs = numpy.linalg.eig(subell)
# sign eigenvals
lambdaa = numpy.sqrt(eigenvals)
plot_no = no_grid*cols+rows+1
ax = fig.add_subplot(no_grid, no_grid, plot_no)
ell = Ellipse(xy = [center[rows],center[cols]], \
width = lambdaa[0]*2, \
height = lambdaa[1]*2, \
angle = numpy.rad2deg(numpy.arccos(eigenvecs[0,0])))
ax.add_artist(ell)
ell.set_clip_box(ax.bbox)
sf = 1.0
height = numpy.sqrt(subell[0,0]) * sf
width = numpy.sqrt(subell[1,1]) * sf
ax.set_xlim(center[rows]-height, center[rows]+height)
ax.set_ylim(center[cols]-width, center[cols]+width)
squared = True
if squared:
x0,x1 = ax.get_xlim()
y0,y1 = ax.get_ylim()
ax.set_aspect(abs(x1-x0)/abs(y1-y0))
ax.plot([0],[0], 'b+')
ell.set_color('b')
ell.set_facecolor('none')
ax.set_xticks(config.axes[cols].get_major_ticks())
ax.set_yticks(config.axes[rows].get_major_ticks())
handle_axes_labels(config, ax, rows, cols)
示例2: calculate_ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def calculate_ellipse(center_x, center_y, covariance_matrix, n_std_dev=3):
values, vectors = np.linalg.eigh(covariance_matrix)
order = values.argsort()[::-1]
values = values[order]
vectors = vectors[:, order]
theta = np.degrees(np.arctan2(*vectors[:, 0][::-1]))
# make all angles positive
if theta < 0:
theta += 360
# Width and height are "full" widths, not radius
width, height = 2 * n_std_dev * np.sqrt(values)
ellipse = Ellipse(
xy=[center_x, center_y],
width=width,
height=height,
angle=theta
)
ellipse.set_alpha(0.3)
ellipse.set_facecolor((1, 0, 0))
return ellipse
示例3: scatter
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def scatter(title="title", xlab="x", ylab="y", data=None):
if data == None:
r = random.random
data = [(r() * 10, r() * 10, r(), r(), r(), r(), r()) for i in range(100)]
figure = Figure()
figure.set_facecolor("white")
axes = figure.add_subplot(111)
if title:
axes.set_title(title)
if xlab:
axes.set_xlabel(xlab)
if ylab:
axes.set_ylabel(ylab)
for i, p in enumerate(data):
p = list(p)
while len(p) < 4:
p.append(0.01)
e = Ellipse(xy=p[:2], width=p[2], height=p[3])
axes.add_artist(e)
e.set_clip_box(axes.bbox)
e.set_alpha(0.5)
if len(p) == 7:
e.set_facecolor(p[4:])
data[i] = p
axes.set_xlim(min(p[0] - p[2] for p in data), max(p[0] + p[2] for p in data))
axes.set_ylim(min(p[1] - p[3] for p in data), max(p[1] + p[3] for p in data))
canvas = FigureCanvas(figure)
stream = cStringIO.StringIO()
canvas.print_png(stream)
return stream.getvalue()
示例4: plot_ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plot_ellipse(x, y, ax, color):
(xy, width, height, angle) = get_ellipse(x, y)
e = Ellipse(xy, width, height, angle)
ax.add_artist(e)
#e.set_clip_box(ax.bbox)
e.set_alpha(0.2)
e.set_facecolor(color)
示例5: show_minimum_bounding_ellipsoids
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def show_minimum_bounding_ellipsoids(Xr, with_sampled = False):
clustellip = Clustered_Sampler(active_samples = Xr,likelihood_constraint=0.0, enlargement= 1.0,no=1)
ellipsoids = clustellip.ellipsoid_set
X0 = [i[0] for i in Xr]
Y0 = [i[1] for i in Xr]
plt.figure()
ax = plt.gca()
points = []
#print len(ellipsoids)
for i in range(len(ellipsoids)):
if ellipsoids[i]!=None:
a, b = np.linalg.eig(ellipsoids[i].covariance_matrix)
c = np.dot(b, np.diag(np.sqrt(a)))
width = np.sqrt(np.sum(c[:,1]**2)) * 2.
height = np.sqrt(np.sum(c[:,0]**2)) * 2.
angle = math.atan(c[1,1] / c[0,1]) * 180./math.pi
points = ellipsoids[i].sample(n_points = 50)
ellipse = Ellipse(ellipsoids[i].centroid, width, height, angle)
ellipse.set_facecolor('None')
ax.add_patch(ellipse)
X = [i[0] for i in points]
Y = [i[1] for i in points]
if with_sampled == True:
plt.plot(X, Y, 'bo')
plt.plot(X0, Y0, 'ro')
plt.show()
示例6: plot_data
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plot_data(data0, label0, title, subtitle, *args):
colors = iter(cm.rainbow(np.linspace(0,1,5)))
plt.clf()
fig = plt.figure()
ax = plt.gca()
if (len(args) == 2):
means, covmats = args
elif (len(args) == 4):
means, covmats, traindata, trainlabel = args
trainlabel = trainlabel.reshape(trainlabel.size)
for i in range(1,6):
cl = next(colors)
plt.scatter(data0[(label0==i).reshape((label0==i).size),0],
data0[(label0==i).reshape((label0==i).size),1],color=cl)
# Draw ellipse with 1 standard deviation
if (len(args) >= 2):
# Compute eigen vectors and value for covmat to plot an ellipse
lambda_, v = np.linalg.eig(covmats[i-1])
lambda_ = np.sqrt(lambda_)
ell = Ellipse(xy=(means[0,i-1], means[1,i-1]),
width=lambda_[0]*2, height=lambda_[1]*2,
angle=np.rad2deg(np.arccos(v[0, 0])))
ell.set_facecolor('none')
ax.add_artist(ell)
#Add mean points
plt.scatter(means[0,i-1], means[1,i-1],c='black',s=30);
if (len(args) == 4):
plt.scatter(traindata[trainlabel==i,0],
traindata[trainlabel==i,1],color=cl,
edgecolor='black')
fig.suptitle(title)
ax.set_title(subtitle,fontsize='10')
fig.show()
return
示例7: plotCovariance
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plotCovariance(center, matrix, color):
eigvalue, eigvector = lng.eig(matrix)
theta = atan2(eigvector[0][1], eigvector[0][0])
ellipse = Ellipse([center[0], center[1]], 2*pow(eigvalue[0], 0.5), 2*pow(eigvalue[1], 0.5), center[2])
ellipse.set_facecolor(color)
fig = plt.gcf()
fig.gca().add_artist(ellipse)
示例8: visualizer
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def visualizer(data, x, y, lengths):
fig = plt.figure()
ax = fig.add_subplot(111)
fig.suptitle("Clustered Results")
colors = plt.get_cmap("gist_rainbow")
norm = col.Normalize(vmin = 0, vmax = len(lengths))
color_map = cm.ScalarMappable(cmap = colors, norm = norm)
index = 0
for i in range(len(lengths)):
plt.scatter(data[index:index + lengths[i], x], data[index:index + lengths[i], y], c = color_map.to_rgba(i))
if lengths[i] != 1:
cov = numpy.cov(data[index:index + lengths[i], x], data[index:index + lengths[i], y], ddof = 0)
else:
cov = numpy.asarray([[0, 0], [0,0]])
values, vectors = numpy.linalg.eig(cov)
angle = numpy.arctan((vectors[0,1] - vectors[1,1])/(vectors[0,0] - vectors[1,0]))
ellipse = Ellipse(xy = (numpy.mean(data[index:index + lengths[i], x]), numpy.mean(data[index:index + lengths[i], y])), width = 2 * 2 * numpy.sqrt(values[0]),
height = 2 * 2 * numpy.sqrt(values[1]), angle = numpy.rad2deg(angle))
ellipse.set_edgecolor(color_map.to_rgba(i))
ellipse.set_facecolor("none")
ax.add_artist(ellipse)
plt.scatter(numpy.mean(data[index:index + lengths[i], x]), numpy.mean(data[index:index + lengths[i], y]), c = color_map.to_rgba(i), marker = 'x')
index += lengths[i]
plt.show()
plt.close()
示例9: drawDef
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def drawDef(dfeat,dy,dx,mindef=0.001,distr="father"):
"""
auxiliary funtion to draw recursive levels of deformation
"""
from matplotlib.patches import Ellipse
pylab.ioff()
if distr=="father":
py=[0,0,2,2];px=[0,2,0,2]
if distr=="child":
py=[0,1,1,2];px=[1,2,0,1]
ordy=[0,0,1,1];ordx=[0,1,0,1]
x1=-0.5+dx;x2=2.5+dx
y1=-0.5+dy;y2=2.5+dy
if distr=="father":
pylab.fill([x1,x1,x2,x2,x1],[y1,y2,y2,y1,y1],"r", alpha=0.15, edgecolor="b",lw=1)
for l in range(len(py)):
aux=dfeat[ordy[l],ordx[l],:].clip(-1,-mindef)
wh=numpy.exp(-mindef/aux[0])/numpy.exp(1);hh=numpy.exp(-mindef/aux[1])/numpy.exp(1)
e=Ellipse(xy=[(px[l]+dx),(py[l]+dy)], width=wh, height=hh, alpha=0.35)
x1=-0.75+dx+px[l];x2=0.75+dx+px[l]
y1=-0.76+dy+py[l];y2=0.75+dy+py[l]
col=numpy.array([wh*hh]*3).clip(0,1)
if distr=="father":
col[0]=0
e.set_facecolor(col)
pylab.gca().add_artist(e)
if distr=="father":
pylab.fill([x1,x1,x2,x2,x1],[y1,y2,y2,y1,y1],"b", alpha=0.15, edgecolor="b",lw=1)
示例10: graficaGrilla
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def graficaGrilla(dataGrilla,name,framesNumber,colour,xPixels,yPixels):
from matplotlib.patches import Ellipse
from pylab import figure, show, savefig
fig = figure()
ax = fig.add_subplot(111, aspect='equal')
# Each row of dataGrilla contains
# N == "framesNumbers" , signal
# A radius of the RF ellipse
# B radius of the RF ellipse
# Angle of the RF ellipse
# X coordinate of the RF ellipse
# Y coordinate of the RF ellipse
ax = fig.add_subplot(111, aspect='equal')
for unit in range(dataGrilla.shape[0]):
eWidth = dataGrilla[unit][framesNumber-1+1]
eHeight = dataGrilla[unit][framesNumber-1+2]
eAngle = dataGrilla[unit][framesNumber-1+3]
eXY = [dataGrilla[unit][framesNumber-1+4], dataGrilla[unit][framesNumber-1+5]]
e = Ellipse(xy=eXY, width=eWidth, height=eHeight, angle=eAngle)
ax.add_artist(e)
e.set_alpha(0.2)
e.set_facecolor(colour)
ax.set_xlim(0, xPixels)
ax.set_ylim(0, yPixels)
savefig(name, dpi=None, bbox_inches='tight')
return 0
示例11: UVellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def UVellipse(u,v,w,a,b,v0):
fig=plt.figure(0)
e1=Ellipse(xy=np.array([0,v0]),width=2*a,height=2*b,angle=0)
e2=Ellipse(xy=np.array([0,-v0]),width=2*a,height=2*b,angle=0)
ax=fig.add_subplot(111,aspect="equal")
ax.plot([0],[v0],"go")
ax.plot([0],[-v0],"go")
ax.plot(u[0],v[0],"bo")
ax.plot(u[-1],v[-1],"bo")
ax.plot(-u[0],-v[0],"ro")
ax.plot(-u[-1],-v[-1],"ro")
ax.add_artist(e1)
e1.set_lw(1)
e1.set_ls("--")
e1.set_facecolor("w")
e1.set_edgecolor("b")
e1.set_alpha(0.5)
ax.add_artist(e2)
e2.set_lw(1)
e2.set_ls("--")
e2.set_facecolor("w")
e2.set_edgecolor("r")
e2.set_alpha(0.5)
ax.plot(u,v,"b")
ax.plot(-u,-v,"r")
ax.hold('on')
示例12: plot
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plot(data, mus=None, sigmas=None, colors='black', figname='fig.png'):
# Create figure
fig = plt.figure()
# Plot data
x = data[:, 0]
y = data[:, 1]
plt.scatter(x, y, 24, c=colors)
# Plot cluster centers
if mus is not None:
x = [float(m[0]) for m in mus]
y = [float(m[1]) for m in mus]
plt.scatter(x, y, 99, c='red')
# Plot ellipses for each cluster
if sigmas is not None:
for sig_ix in range(K):
ax = fig.gca()
cov = np.array(sigmas[sig_ix])
lam, v = np.linalg.eig(cov)
lam = np.sqrt(lam)
ell = Ellipse(xy=(x[sig_ix], y[sig_ix]),
width=lam[0]*4, height=lam[1]*4,
angle=np.rad2deg(np.arccos(v[0, 0])),
color='blue')
ell.set_facecolor('none')
ax.add_artist(ell)
# Save figure
fig.savefig(figname)
示例13: plotCovEllipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plotCovEllipse(cov, pos, nstd=2, ax=None, with_line=False, **kwargs):
"""
Plots an `nstd` sigma error ellipse based on the specified covariance
matrix (`cov`). Additional keyword arguments are passed on to the
ellipse patch artist.
Parameters
----------
cov : The 2x2 covariance matrix to base the ellipse on
pos : The location of the center of the ellipse. Expects a 2-element
sequence of [x0, y0].
nstd : The radius of the ellipse in numbers of standard deviations.
Defaults to 2 standard deviations.
ax : The axis that the ellipse will be plotted on. Defaults to the
current axis.
Additional keyword arguments are pass on to the ellipse patch.
Returns
-------
A matplotlib ellipse artist
"""
def eigsorted(cov):
vals, vecs = np.linalg.eigh(cov)
order = vals.argsort()[::-1]
return vals[order], vecs[:, order]
if ax is None:
ax = plt.gca()
# largest eigenvalue is first
vals, vecs = eigsorted(cov)
theta = np.degrees(np.arctan2(*vecs[:, 0][::-1]))
# Width and height are "full" widths, not radius
width, height = 2 * nstd * np.sqrt(vals)
ellip = Ellipse(xy=pos, width=width, height=height, angle=theta, **kwargs)
if 'alpha' not in kwargs.keys():
ellip.set_alpha(0.3)
if 'color' not in kwargs.keys():# and 'c' not in kwargs.keys():
ellip.set_facecolor('red')
ax.add_patch(ellip)
# THEN just f***ing plot an invisible line across the ellipse.
if with_line:
# brute forcing axes limits so they contain ellipse patch
# maybe a cleaner way of doing this, but I couldn't work it out
x_extent = 0.5*(abs(width*np.cos(np.radians(theta))) +
abs(height*np.sin(np.radians(theta))))
y_extent = 0.5*(abs(width*np.sin(np.radians(theta))) +
abs(height*np.cos(np.radians(theta))))
lx = pos[0] - x_extent
ux = pos[0] + x_extent
ly = pos[1] - y_extent
uy = pos[1] + y_extent
ax.plot((lx, ux), (ly, uy), alpha=0.)
return ellip
示例14: draw
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def draw(self, axes, figure, color):
mycirc = Ellipse(self.center, self.width, self.height, facecolor='none', edgecolor=color)
mycirc.set_linewidth(1)
mycirc.set_alpha(1)
mycirc.set_facecolor('none')
mycirc.set_hatch('//')
circ = axes.add_artist(mycirc)
figure.canvas.draw()
return circ
示例15: plot_ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_facecolor [as 别名]
def plot_ellipse(w,h,b):
fig = plt.figure(0)
fig.clf()
ax = fig.add_subplot(111, aspect='equal')
e = Ellipse((0.,0.),w,h)
e.set_facecolor((0.,0.,b))
ax.add_artist(e)
ax.set_xlim(-1., 1.)
ax.set_ylim(-1., 1.)