本文整理汇总了Python中matplotlib.patches.Circle类的典型用法代码示例。如果您正苦于以下问题:Python Circle类的具体用法?Python Circle怎么用?Python Circle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Circle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_body
def write_body(self):
try:
from matplotlib.path import Path
except ImportError:
Path = None
from matplotlib.patches import Circle, Polygon
else:
from matplotlib.patches import Circle, PathPatch
indices = self.X[:, 2].argsort()
for a in indices:
xy = self.X[a, :2]
if a < self.natoms:
r = self.d[a] / 2
if ((xy[1] + r > 0) and (xy[1] - r < self.h) and
(xy[0] + r > 0) and (xy[0] - r < self.w)):
circle = Circle(xy, r, facecolor=self.colors[a])
circle.draw(self.renderer)
else:
a -= self.natoms
c = self.T[a]
if c != -1:
hxy = self.D[c]
if Path is None:
line = Polygon((xy + hxy, xy - hxy))
else:
line = PathPatch(Path((xy + hxy, xy - hxy)))
line.draw(self.renderer)
示例2: animate
def animate(currentNode = currentNode):
while 1:
newNode = q.get()
if currentNode: currentNode.remove()
circle = Circle(newNode,0.1)
currentNode = ax.add_patch(circle)
circle.set_fc('r')
fig.canvas.draw()
示例3: circle
def circle(xy=None, x=None, y=None, **kwargs):
if xy is None:
if x is None or y is None:
raise 'circle: need x and y'
xy = array([x,y])
c = Circle(xy=xy, **kwargs)
a=gca()
c.set_clip_box(a.bbox)
a.add_artist(c)
return c
示例4: draw_vswr_circles
def draw_vswr_circles(self, vswr_radii, labels=False):
for r in vswr_radii:
c = Circle((0, 0), r, ls='dashed', **self.patch_options_light)
c.set_clip_path(self.smith_circle)
c.set_clip_box(self.ax.bbox)
self.ax.add_patch(c)
if labels:
for r in vswr_radii:
if r > 0:
vswr = (1 + r)/(1 - r)
self.ax.text(0, r, '%.1f' % vswr, **self.label_options)
示例5: make_animation_frames
def make_animation_frames(name, semimajor, planet_radius, star_radius, star_color, orbital_period):
#not affiliated with Animal Planet.
center = np.array([0.5,0.5])
angle = np.random.uniform(0, 2*np.pi)
planet_center = center+semimajor*np.array([1,0])
fig = Figure(figsize=(6,6))
axis = fig.add_subplot(1, 1, 1)
star = Circle(center, radius=star_radius, color=star_color)
orbit = Circle(center, radius=semimajor, fill=False, linestyle='dashed', color='gray')
planet = Circle(planet_center, radius=planet_radius, color='green')
axis.add_patch(star)
axis.add_patch(orbit)
axis.add_patch(planet)
axis.axis('off')
filenames = []
#set 50 days to be 5 seconds
orbital_period = orbital_period/100.*5.
#let's put the period in seconds
fps = 100.
print 'orbital period = ', orbital_period
nframe = int(orbital_period*fps)
#round off
orbital_period = nframe/fps
omega = 2*np.pi/orbital_period
angles = np.linspace(0, 2*np.pi, nframe)
if not os.path.exists("frames"):
os.makekdir("frames")
if not os.path.exists("gifs"):
os.makekdir("gifss")
print angles
print "nframe = ", nframe
for i,theta in enumerate(angles):
canvas = FigureCanvas(fig)
planet.center = center+semimajor*np.array([np.cos(theta),np.sin(theta)])
filename = ("frames/%.4d_"%i)+remove_space(name)+'.png'
fig.savefig(filename)
filenames.append(filename)
#animate
gifname = "gifs/%s.gif" % remove_space(name)
frame_names = " ".join(filenames)
cmd = "convert -delay 1 %s %s" % (frame_names, gifname)
print cmd
os.system(cmd)
示例6: add_breadcrumb
def add_breadcrumb(self):
""" Adds a breadcrumb """
c = Circle(self._loc, radius = 16.25)
c.set_facecolor('0.65') # grey
c.set_edgecolor('black')
c.set_zorder(zorders['breadcrumbs'])
c.set_fill(True)
self.view.add_artist(c)
self.breadcrumbs.append(c)
self.draw()
示例7: scatter_plot
def scatter_plot(self, equators=True, tagging=True, depth_cap=None):
if depth_cap is None:
depth_cap = self.height
fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(111, projection="3d")
plt.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)
xs = [self.nodes[self.root].coord.x]
ys = [self.nodes[self.root].coord.y]
zs = [self.nodes[self.root].coord.z]
plot_color_board = ["blue", "red", "yellow", "green", "black"]
font0 = FontProperties()
font0.set_size(8)
current_generation = deque([self.root])
next_generation = True
while next_generation:
next_generation = deque()
while current_generation:
n = current_generation.popleft()
if self.nodes[n].depth <= depth_cap:
xs.append(self.nodes[n].coord.x)
ys.append(self.nodes[n].coord.y)
zs.append(self.nodes[n].coord.z)
if tagging:
ax.text(self.nodes[n].coord.x + 0.01,
self.nodes[n].coord.y + 0.01,
self.nodes[n].coord.z + 0.01,
("n{0}".format(n)), fontproperties=font0)
for child in self.nodes[n].children:
next_generation.append(child)
if self.nodes[n].depth <= depth_cap:
xe = [self.nodes[n].coord.x, self.nodes[child].coord.x]
ye = [self.nodes[n].coord.y, self.nodes[child].coord.y]
ze = [self.nodes[n].coord.z, self.nodes[child].coord.z]
ax.plot(xe, ye, ze, plot_color_board[self.nodes[n].depth % 5])
current_generation = next_generation
ax.scatter(xs, ys, zs, c="r", marker="o")
global_radius = self.nodes[self.root].radius * 1.12
if equators:
for axis in ["x", "y", "z"]:
circle = Circle((0, 0), global_radius * 1.1)
circle.set_clip_box(ax.bbox)
circle.set_edgecolor("gray")
circle.set_alpha(0.3)
circle.set_facecolor("none") # "none" not None
ax.add_patch(circle)
art3d.pathpatch_2d_to_3d(circle, z=0, zdir=axis)
ax.set_xlim([-1.2 * global_radius, 1.2 * global_radius])
ax.set_ylim([-1.2 * global_radius, 1.2 * global_radius])
ax.set_zlim([-1.2 * global_radius, 1.2 * global_radius])
ax.set_xlabel("X Label")
ax.set_ylabel("Y Label")
ax.set_zlabel("Z Label")
plt.show()
示例8: circle
def circle( xy, radius, color="lightsteelblue", facecolor="none", alpha=1, ax=None ):
""" add a circle to ax= or current axes
"""
# from .../pylab_examples/ellipse_demo.py
e = Circle( xy=xy, radius=radius )
if ax is None:
ax = plt.gca() # ax = subplot( 1,1,1 )
ax.add_artist(e)
e.set_clip_box(ax.bbox)
e.set_edgecolor( color )
e.set_facecolor( facecolor ) # "none" not None
e.set_alpha( alpha )
示例9: Annotate
class Annotate(object):
def __init__(self):
self.ax = plt.gca()
# self.rect = Rectangle((0,0), 1, 1)
self.circ = Circle((0,0), 1, alpha=0.1)
self.x0 = None
self.y0 = None
self.x1 = None
self.y1 = None
# self.ax.add_patch(self.rect)
self.ax.add_patch(self.circ)
self.press = None
self.ax.figure.canvas.mpl_connect('button_press_event', self.on_press)
self.ax.figure.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.ax.figure.canvas.mpl_connect('button_release_event', self.on_release)
def on_press(self, event):
print 'press'
self.press = 1
self.x0 = event.xdata
self.y0 = event.ydata
def on_motion(self, event):
if self.press is None:
return
self.x1 = event.xdata
self.y1 = event.ydata
radius = ((self.x1 - self.x0)**2 + (self.y1 - self.y0)**2)**0.5
self.circ.set_radius(radius)
self.circ.center = self.x0, self.y0
# ###self.rect.set_width(self.x1 - self.x0)
# ###self.rect.set_height(self.y1 - self.y0)
# ###self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
def on_release(self, event):
print 'release'
self.press = None
self.x1 = event.xdata
self.y1 = event.ydata
radius = ((self.x1 - self.x0) ** 2 + (self.y1 - self.y0) ** 2) ** 0.5
self.circ.set_radius(radius)
self.circ.center = self.x0, self.y0
# ###self.rect.set_width(self.x1 - self.x0)
# ###self.rect.set_height(self.y1 - self.y0)
# ###self.rect.set_xy((self.x0, self.y0))
self.ax.figure.canvas.draw()
示例10: __init__
def __init__(self, axes, sim, type_to_radius, type_to_color):
assert len(type_to_radius) == len(type_to_color)
particle_types_arr = sim.types
self._typeToRadius = type_to_radius
self._typeToColor = type_to_color
self._particleCircles = []
self._sim = sim
for particleType in particle_types_arr:
c = Circle((0, 0, 0), type_to_radius[particleType], )
c.set_color(self._typeToColor[particleType])
self._particleCircles.append(c)
axes.add_patch(c)
axes.set_xlim([0, sim.domain_size[0]])
axes.set_ylim([0, sim.domain_size[1]])
axes.set_aspect('equal')
示例11: __init__
class SelectablePoint:
def __init__(self, xy, label, fig):
self.point = Circle( (xy[0], xy[1]), .25, figure=fig)
self.label = label
self.cidpress = self.point.figure.canvas.mpl_connect('button_press_event', self.onClick)
def onClick(self, e):
if self.point.contains(e)[0]:
print self.label
示例12: draw_chart_axes
def draw_chart_axes(self):
# make outer circle
self.smith_circle = Circle((0, 0), 1, transform=self.ax.transData, fc='none',
**self.patch_options_axis)
self.ax.add_patch(self.smith_circle)
# make constant r=1 circle
z0_circle = Circle((0.5, 0), 0.5, transform=self.ax.transData, fc='none',
**self.patch_options_axis)
z0_circle.set_clip_path(self.smith_circle)
z0_circle.set_clip_box(self.ax.bbox)
self.ax.add_patch(z0_circle)
# make x-axis
line = Line2D([-1,1],[0,0], **self.patch_options_axis)
line.set_clip_path(self.smith_circle)
line.set_clip_box(self.ax.bbox)
self.ax.add_line(line)
示例13: myCorrPlot
def myCorrPlot(df):
"""
Correlation plot ( ~ corrplot with R)
Takes a Pandas DataFrame as input and returns
the plot which can then be shown with
plot.show(), saved to a file with plot.savefig(), or
manipulated in any other standard matplotlib way.
Forked from https://github.com/louridas/corrplot
"""
plt.figure(1)
ax = plt.subplot(1, 1, 1, aspect='equal')
poscm = cm.get_cmap('Blues')
negcm = cm.get_cmap('Reds')
labels = df.columns
for pair in combinations(labels, 2):
corr = pearsonr(df[pair[0]].values, df[pair[1]].values)[0]
clrmap = poscm if corr >= 0 else negcm
circle = Circle((labels.get_loc(pair[0]),labels.get_loc(pair[1])), radius = 0.4)
circle.set_edgecolor('black')
circle.set_facecolor(clrmap(np.abs(corr)))
mirrorCircle = Circle((labels.get_loc(pair[1]),labels.get_loc(pair[0])), radius = 0.4)
mirrorCircle.set_edgecolor('black')
mirrorCircle.set_facecolor(clrmap(np.abs(corr)))
ax.add_artist(circle)
ax.add_artist(mirrorCircle)
ax.set_xlim(-1, len(labels))
ax.set_ylim(-1, len(labels))
ax.xaxis.tick_top()
xtickslocs = np.arange(len(labels))
ax.set_xticks(xtickslocs)
ax.set_xticklabels(labels, rotation=30, fontsize='small', ha='left')
ax.invert_yaxis()
ytickslocs = np.arange(len(labels))
ax.set_yticks(ytickslocs)
ax.set_yticklabels(labels, fontsize='small')
return plt
示例14: draw_impedance_circles
def draw_impedance_circles(self, intercept_x_coords, intercept_angles, labels=False):
r_circle_coords, x_circle_coords, rs, xs = self._impedance_circle_coords(intercept_x_coords, intercept_angles)
for center, radius in chain(r_circle_coords, x_circle_coords):
c = Circle(center, radius, **self.patch_options_dark)
c.set_clip_path(self.smith_circle)
c.set_clip_box(self.ax.bbox)
self.ax.add_patch(c)
if labels:
for x, r in zip(intercept_x_coords, rs):
self.ax.text(x + 0.04, 0.03, '%.0f' % round(self.z0*r), **self.label_options)
for a, x in zip(intercept_angles, xs):
r = (a - 90) if x > 0 else (a + 90)
a = np.radians(a)
d = 1.04
self.ax.text(d*cos(a), d*sin(a), '%.0fj' % round(self.z0*x), rotation=r, **self.label_options)
示例15: draw_admittance_circles
def draw_admittance_circles(self, intercept_x_coords, intercept_angles, labels=False):
r_circle_coords, x_circle_coords, rs, xs = self._impedance_circle_coords(intercept_x_coords, intercept_angles)
# admittance circles have same coords as impedance ones, except flipped
# on the y-axis
for (x, y), radius in chain(r_circle_coords, x_circle_coords):
c = Circle((-x, -y), radius, **self.patch_options_light)
c.set_clip_path(self.smith_circle)
c.set_clip_box(self.ax.bbox)
self.ax.add_patch(c)
if labels:
for x, r in zip(intercept_x_coords, rs):
self.ax.text(-x, 0, '%.1f' % (1/(50*r)), **self.label_options)
for a, x in zip(intercept_angles, xs):
r = (a - 90) if x < 0 else (a + 90)
a = np.radians(a)
self.ax.text(cos(pi - a), sin(pi - a), '%.1f' % (1/(50*x)), rotation=r, **self.label_options)