本文整理汇总了Python中matplotlib.patches.Ellipse.set_fill方法的典型用法代码示例。如果您正苦于以下问题:Python Ellipse.set_fill方法的具体用法?Python Ellipse.set_fill怎么用?Python Ellipse.set_fill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Ellipse
的用法示例。
在下文中一共展示了Ellipse.set_fill方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: covarianceEllipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_fill [as 别名]
def covarianceEllipse(mean, covar, scale=1.0):
eval, evec = np.linalg.eig(covar)
angles = np.degrees(np.arctan(evec[1,:] / evec[0,:]))
q1 = np.flatnonzero((angles >= 0) & (angles < 90))[0]
q2 = 1 - q1
q1Angle = angles[q1]
q1Length = np.sqrt(eval[q1])
q2Length = np.sqrt(eval[q2])
e = Ellipse(xy=mean, angle=q1Angle,
width=q1Length*scale, height=q2Length*scale)
e.set_fill(False)
e.set_edgecolor("black")
e.set_alpha(1.0)
e.set_lw(2)
e.set_ls("dashed")
return e
示例2: ellipses2D
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_fill [as 别名]
def ellipses2D(self, colors):
from matplotlib.patches import Ellipse
ellipses = []
for i, ((weight, mean, _), covar) in enumerate(zip(self, self._get_covars())):
(val, vect) = eig(covar)
el = Ellipse(mean,
3.5 * sqrt(val[0]),
3.5 * sqrt(val[1]),
180. * arctan2(vect[1, 0], vect[0, 0]) / pi,
fill=False,
linewidth=2)
el.set_facecolor(colors[i])
el.set_fill(True)
el.set_alpha(0.5)
ellipses.append(el)
return ellipses
示例3: plotCovarianceCorner
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_fill [as 别名]
def plotCovarianceCorner(covariance,labels=None,percentiles=[67,95,99.7],alphas=[1.,0.7,0.5],addToExisitingAxes=None,fillEllipses=True,
univariateAlpha=1.,ellipseFaceColour='k',ellipseEdgeColour='k',univariateColour='k',maxStds=None,
means=None,labelSize=20,tickSize=20):
nVariate = len(covariance)
if labels == None:
labels = ['' for _ in range(nVariate)]
## work out the critical values according to the provided percentiles
criticals = []
for p in percentiles:
criticals.append(spst.chi2.ppf(q=p/100.,df=2))
#plot in descending percentile (smaller ellipses on top)
criticals = np.sort(criticals)
alphas = np.sort(alphas)[::-1]
stds = np.sqrt(np.diag(covariance))
#sensible widths for plots
if np.any(maxStds == None):
widths = stds * np.max(np.sqrt(criticals)) * 1.2
else:
widths = maxStds * np.max(np.sqrt(criticals)) * 1.2
widths = np.array(widths)
if means is None:
means = np.zeros_like(np.diag(covariance))
if np.any(addToExisitingAxes == None):
fig,axs = plot.subplots(nVariate,nVariate)
else:
fig,axs = addToExisitingAxes
# for i in range(nVariate):
# for j in range(nVariate):
for i,j in np.ndindex(nVariate,nVariate):
if j>i:
#hide upper right triangle
axs[i,j].axis('off')
elif i == j:
#univariate plots
var = covariance[i,j]
xs = np.linspace(-widths[i], widths[i],1000) + means[i]
# ys = np.exp(-0.5*((xs-means[i])**2)/var)
ys = spst.norm.pdf(xs,loc=means[i],scale=np.sqrt(var))
# ys = ys/np.max(ys)
axs[i,j].plot(xs,ys,color=univariateColour,alpha=univariateAlpha)
axs[i,j].set_xlim(-widths[i]+means[i], widths[i]+means[i])
# axs[i,j].set_ylim(0,1.1)
axs[i,j].set_yticks([])
else:
#bivariate plots
bivCov = np.array([[covariance[i,i],covariance[i,j]],
[covariance[j,i],covariance[j,j]]])
eigVals, eigVecs = np.linalg.eig(bivCov)
princEigVec = eigVecs[:,0]
angle = np.arctan(princEigVec[0]/princEigVec[1])*(180./np.pi)
#np.arctan2()
#np.rad2deg()
for en,c in enumerate(criticals):
e = Ellipse((means[j],means[i]), 2.*np.sqrt(c*eigVals[0]), 2.*np.sqrt(c*eigVals[1]),angle=angle)
e.set_alpha(alphas[en])
e.set_fill(fillEllipses)
e.set_edgecolor(ellipseEdgeColour)
e.set_facecolor(ellipseFaceColour)
axs[i,j].add_artist(e)
axs[i,j].set_xlim(-widths[j]+means[j],widths[j]+means[j])
axs[i,j].set_ylim(-widths[i]+means[i],widths[i]+means[i])
#don't overcrowd the axes
axs[i,j].set_xticks(np.linspace(-misc.roundToOneSigFig(widths[j]*0.5),misc.roundToOneSigFig(widths[j]*0.5),3) + means[j])
axs[i,j].set_yticks(np.linspace(-misc.roundToOneSigFig(widths[i]*0.5),misc.roundToOneSigFig(widths[i]*0.5),3) + means[i])
#only label the left most and bottom most plots
if i>0 and j == 0:
axs[i,j].set_ylabel(labels[i],size=labelSize)
for tick in axs[i,j].yaxis.get_major_ticks():
tick.label1.set_fontsize(tickSize)
if i == nVariate - 1:
axs[i,j].set_xlabel(labels[j],size=labelSize)
#.........这里部分代码省略.........
示例4: Ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_fill [as 别名]
# for GMM
# covar = clf.covars_[i][0:2, 0:2]
# for all modes of GMM
covar = clf._get_covars()[i][0:2, 0:2]
v, w, = linalg.eigh(covar)
angle = np.arctan2(w[0][1], w[0][0]) * 180.0 / np.pi
angle_out[i] = angle
ell = Ellipse(means, v[0], v[1], angle)
ax.add_artist(ell)
ell.set_clip_box(ax.bbox)
ell.set_facecolor('None')
ell.set_fill(False)
ell.set_color(color_iter.next())
# ell.set_alpha(.25)
plt.xlim((np.min(tmid), np.max(tmid)))
plt.ylim((0,360))
plt.scatter(xo, yo, c='k', s=(zo / np.nanmax(r1)*20.)**2., alpha=0.6)
plt.show()
plt.figure()
h = plt.hist(angle_out)
plt.show()