本文整理汇总了Python中matplotlib.patches.Ellipse.set_clip_box方法的典型用法代码示例。如果您正苦于以下问题:Python Ellipse.set_clip_box方法的具体用法?Python Ellipse.set_clip_box怎么用?Python Ellipse.set_clip_box使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Ellipse
的用法示例。
在下文中一共展示了Ellipse.set_clip_box方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scatter
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [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()
示例2: plot_error_ellipse_xy
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def plot_error_ellipse_xy(cls, figure, x, y, abom, style):
"""
plots standard error ellipse
x, y : position of center of ellipse
abom : a, b, om parameters of ellipse
method do not handle axes orientation (self.figure.axesXY)
"""
from matplotlib.patches import Ellipse
from math import pi
a, b, om = abom
#print "swapXY:", figure.is_swap_xy()
if figure.is_swap_xy():
y, x = x, y
om = pi/2 - om
#om = om - pi/2
ell = Ellipse((x, y), 2*a, 2*b, om*180.0/pi) #?
#transform=self.axes.transData + self.ellTrans)
figure.set_style(style, ell)
ell.set_clip_box(figure.gca().bbox) # cut edges outside axes box?
figure.gca().add_artist(ell)
示例3: plot_galaxies
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def plot_galaxies(self, ax, gals=None):
if gals == None:
gals = self.galaxies
for gal in gals:
e = Ellipse((gal.x, gal.y), gal.a(), gal.b(), angle=gal.theta, linewidth=2, fill=True)
ax.add_artist(e)
e.set_clip_box(ax.bbox)
示例4: test_polar_coord_annotations
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def test_polar_coord_annotations():
# You can also use polar notation on a catesian axes. Here the
# native coordinate system ('data') is cartesian, so you need to
# specify the xycoords and textcoords as 'polar' if you want to
# use (theta, radius)
from matplotlib.patches import Ellipse
el = Ellipse((0,0), 10, 20, facecolor='r', alpha=0.5)
fig = plt.figure()
ax = fig.add_subplot( 111, aspect='equal' )
ax.add_artist( el )
el.set_clip_box( ax.bbox )
ax.annotate('the top',
xy=(np.pi/2., 10.), # theta, radius
xytext=(np.pi/3, 20.), # theta, radius
xycoords='polar',
textcoords='polar',
arrowprops=dict(facecolor='black', shrink=0.05),
horizontalalignment='left',
verticalalignment='baseline',
clip_on=True, # clip to the axes bounding box
)
ax.set_xlim( -20, 20 )
ax.set_ylim( -20, 20 )
示例5: plot_qudratic_confidence_region_2D_ellipsoid
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [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)
示例6: ErrEllipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
class ErrEllipse(object):
"""
A class for creating and drawing an ellipse in matplotlib.
"""
def __init__(self, x_cen, y_cen, a, b, pa, color='b'):
"""
:param x_cen: x coordinate at center of the ellipse
:param y_cen: y coordinate at center of the ellipse
:param a: size of semi-major axes of the ellipse
:param b: size of semi-minor axes of the ellipse
:param pa: position angle of a to x (90 ==> a is same orientation as x)
"""
self.center = (x_cen, y_cen)
self.a = max(a, 10)
self.b = max(b, 10)
self.pa = pa
angle = self.pa - 90
self.artist = Ellipse(self.center, self.a, self.b, angle=angle,
linewidth=3, edgecolor=color, facecolor='#E47833',
alpha=0.1)
def add_to_axes(self, axes):
self.artist.set_clip_box(axes.bbox)
axes.add_patch(self.artist)
示例7: PlotLens
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def PlotLens(self,CenterXY, thickness, LensHeight, rotation, alpha=0.5):
# Definition to plot a lens.
lens = Ellipse(xy=CenterXY, width=thickness, height=LensHeight, angle=-rotation)
self.ax.add_artist(lens)
lens.set_clip_box(self.ax.bbox)
lens.set_alpha(alpha)
return True
示例8: plot
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def plot(self, ax, color):
"""
Return an ellipse object for plotting, add to ax, with color
"""
e = Ellipse(xy = array([self.pos.x, self.pos.y]), width = self.width, height = self.length, angle = self.lengthAngle/pi*180)
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_facecolor(color)
return e
示例9: draw_ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def draw_ellipse(a, m, S):
v, w = np.linalg.eigh(S)
u = w[0] / np.linalg.norm(w[0])
angle = (180.0 / np.pi) * np.arctan(u[1] / u[0])
e = Ellipse(m, 2.0 * np.sqrt(v[0]), 2.0 * np.sqrt(v[1]),
180.0 + angle, color = 'k')
a.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_alpha(0.5)
示例10: ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def ellipse(xy=None, x=None, y=None, **kwargs):
if xy is None:
if x is None or y is None:
raise 'ellipse: need x and y'
xy = array([x,y])
c = Ellipse(xy=xy, **kwargs)
a=gca()
c.set_clip_box(a.bbox)
a.add_artist(c)
return c
示例11: draw_ellipse
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def draw_ellipse(axes, cluster):
x = 0.5 * (cluster.data[0] + cluster.data[1])
rng = cluster.data[1] - cluster.data[0]
y = .25 + (cluster.level - 1) * 1.5 / (max_level - 1)
height = 1.5 / (max_level - 1)
ell = Ellipse(xy=[x,y], width=rng, height=height, angle=0)
axes.add_artist(ell)
ell.set_clip_box(axes.bbox)
ell.set_alpha(0.5)
ell.set_facecolor([0, 0, 1.0])
示例12: ellipses
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def ellipses(self, data, color='blue', width=0.01, height=0.01):
for point in data:
x, y = point[:2]
dx = point[2] if len(point)>2 else width
dy = point[3] if len(point)>3 else height
ellipse = Ellipse(xy=(x, y), width=dx, height=dy)
self.ax.add_artist(ellipse)
ellipse.set_clip_box(self.ax.bbox)
ellipse.set_alpha(0.5)
ellipse.set_facecolor(color)
return self
示例13: plot
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def plot(self, fig, iteration, clusters, x, mu, sigma):
plt.clf()
ax=fig.add_subplot(111)
#ax = plt.axes([0, 0, 1, 1])
plt.xlim(0, 10)
plt.ylim(0, 10)
ax.axes.get_xaxis().set_visible(False)
ax.axes.get_yaxis().set_visible(False)
#plt.xlabel('x')
#plt.ylabel('y')
plt.title(self.title)
#plt.title(r'$$\sigma = \begin{matrix} 1 2 \\ 3 4 \end{matrix}$$')
for clust in clusters:
#print("Cluster")
#print(clust.mu())
#print(clust.sigma())
sig=clust.sigma()
cmu=clust.mu()
a,b=numpy.linalg.eig(sig)
angle = math.pi/2
if(b[0,0] != 0):
angle = -math.atan(b[0,1]/b[0,0])
#print("Ellipse: %f x %f (%f degrees)" % (a[1], a[0], math.degrees(angle) ))
ell = Ellipse(xy=clust.mu(), width=a[0]*2.5, height=a[1]*2.5, angle=math.degrees(angle))
ax.add_artist(ell)
ell.set_clip_box(ax.bbox)
ell.set_alpha(0.5)
ell.set_facecolor('blue')
ax.arrow(cmu[0], cmu[1], sig[0,0], sig[0,1], head_width=.2, head_length=.4, fc='k', ec='k')
ax.arrow(cmu[0], cmu[1], sig[1,0], sig[1,1], head_width=.2, head_length=.4, fc='k', ec='k')
#label= "$\\alpha = %.4f$\n$\\mu_1 = %.2f, \\mu_2 = %.2f$\n$\\Sigma_{1 1} = %.2f, \\Sigma_{2 2} = %.2f$\n$\\Sigma_{1 2} = \\Sigma_{2 1} = %.2f$" % (clust.learning_rate,
# cmu[0], cmu[1], sig[0,0], sig[1,1], sig[0,1])
#label= "alpha = %.4f\nmu 1 = %.2f, mu 2 = %.2f\nSigma 1 1 = %.2f, Sigma 2 2 = %.2f" % (clust.learning_rate, cmu[0], cmu[1], sig[0,0], sig[1,1])
#label = r'$$\sigma = \begin{bmatrix} 1 2 \\ 3 4 \end{bmatrix}$$'
c = clustering.cluster.Cluster()
c.pack(mu, sigma)
label = self.legend_tex() % (clust.learning_rate, mu[0], mu[1], cmu[0], cmu[1], sigma[0,0], sigma[0,1], sigma[1,0], sigma[1,1], sig[0,0], sig[0,1], sig[1,0], sig[1,1], c.differential_entropy(), clust.differential_entropy())
#h1 = c.differential_entropy()
#h2 = clust.differential_entropy()
#t=ax.text(cmu[0],cmu[1]-1, label, ha="center", va="center", size=15,bbox=bbox_props)
#ax.annotate("$$ \\Sigma = \\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix} $$", xy=(0, 0), xytext=(1, 1))
bbox_props = dict(boxstyle="round,pad=0.3", fc="cyan", ec="b", lw=2)
t=ax.text(0.5,9.5, label, ha="left", va="top", size=10, bbox=bbox_props)
#t.get_bbox_patch().set_boxstyle("round", pad=0.6)
#ax.text(1,5, "$$array = \\begin{bmatrix} 2 & 3 \\\\ 4 & 5 \\end{bmatrix}$$")
#
l = plt.plot([x[0],x[0]], [x[1],x[1]],'ro')
return l
示例14: draw_ell
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def draw_ell(cov, xy, color):
u, v = np.linalg.eigh(cov)
angle = np.arctan2(v[0][1], v[0][0])
angle = (180 * angle / np.pi)
# here we time u2 with 5, assume 95% are in this ellipse
# I copy this coef from the matlab script~:)
#there should be a function to calculate it, find it yourself~
u2 = 5 * (u ** 0.5)
e = Ellipse(xy, u2[0], u2[1], angle)
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_facecolor('none')
e.set_edgecolor(color)
示例15: plot_network_activity
# 需要导入模块: from matplotlib.patches import Ellipse [as 别名]
# 或者: from matplotlib.patches.Ellipse import set_clip_box [as 别名]
def plot_network_activity(self, stimulus_input=None):
"""Plot the activity of the whole network on a specific stimulus.
Shows activations of both layers
"""
if stimulus_input is None:
stimulus_input = (0, ) * self.R
# Compute activity of network on the stimulus
self.get_network_response(stimulus_input=stimulus_input)
# Do a subplot, second layer on top, first layer on bottom
plt.figure()
ax_layertwo = plt.subplot(2, 1, 1)
ax_layerone = plt.subplot(2, 1, 2)
# Plot the level two activation, use a bar, easier to read
ax_layertwo.bar(
np.arange(self.M_layer_two), self.current_layer_two_response)
# Plot the activation of the level one subnetwork (and of the individual responses at level two)
M_sqrt = int(self.M_layer_one**0.5)
# Level one
im = ax_layerone.imshow(
self.current_layer_one_response[:int(M_sqrt**2)].reshape(
M_sqrt, M_sqrt).T,
origin='lower',
aspect='equal',
cmap='RdBu_r',
interpolation='nearest')
im.set_extent((-np.pi, np.pi, -np.pi, np.pi))
ax_layerone.set_xticks((-np.pi, -np.pi / 2, 0, np.pi / 2., np.pi))
ax_layerone.set_xticklabels((r'$-\pi$', r'$-\frac{\pi}{2}$', r'$0$',
r'$\frac{\pi}{2}$', r'$\pi$'))
ax_layerone.set_yticks((-np.pi, -np.pi / 2, 0, np.pi / 2., np.pi))
ax_layerone.set_yticklabels((r'$-\pi$', r'$-\frac{\pi}{2}$', r'$0$',
r'$\frac{\pi}{2}$', r'$\pi$'))
e = Ellipse(xy=stimulus_input, width=0.4, height=0.4)
ax_layerone.add_artist(e)
e.set_clip_box(ax_layerone.bbox)
e.set_alpha(0.5)
e.set_facecolor('white')
e.set_transform(ax_layerone.transData)
plt.show()