本文整理汇总了Python中matplotlib.pyplot.Circle方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.Circle方法的具体用法?Python pyplot.Circle怎么用?Python pyplot.Circle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.Circle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_figure
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def test_figure(self):
writer = SummaryWriter()
figure, axes = plt.figure(), plt.gca()
circle1 = plt.Circle((0.2, 0.5), 0.2, color='r')
circle2 = plt.Circle((0.8, 0.5), 0.2, color='g')
axes.add_patch(circle1)
axes.add_patch(circle2)
plt.axis('scaled')
plt.tight_layout()
writer.add_figure("add_figure/figure", figure, 0, close=False)
assert plt.fignum_exists(figure.number) is True
writer.add_figure("add_figure/figure", figure, 1)
assert plt.fignum_exists(figure.number) is False
writer.close()
示例2: _draw_topos_one_sub
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def _draw_topos_one_sub(self, fig, sub_id, buses_z, elements, bus_vect):
fig, ax = fig
res_sub = []
# I plot the buses
for bus_id, z_bus in enumerate(buses_z):
bus_color = '#ff7f0e' if bus_id == 0 else '#1f77b4'
bus_circ = plt.Circle((z_bus.real, z_bus.imag), self.bus_radius, color=bus_color, fill=True)
ax.add_artist(bus_circ)
# i connect every element to the proper bus with the proper color
for el_nm, dict_el in elements.items():
this_el_bus = bus_vect[dict_el["sub_pos"]] -1
if this_el_bus >= 0:
color = '#ff7f0e' if this_el_bus == 0 else '#1f77b4'
ax.plot([buses_z[this_el_bus].real, dict_el["z"].real],
[ buses_z[this_el_bus].imag, dict_el["z"].imag],
color=color, alpha=self.alpha_obj)
return []
示例3: plot_colored_circles
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def plot_colored_circles(ax, prng, nb_samples=15):
"""Plot circle patches.
NB: draws a fixed amount of samples, rather than using the length of
the color cycle, because different styles may have different numbers
of colors.
"""
for sty_dict, j in zip(plt.rcParams['axes.prop_cycle'], range(nb_samples)):
ax.add_patch(plt.Circle(prng.normal(scale=3, size=2),
radius=1.0, color=sty_dict['color']))
# Force the limits to be the same across the styles (because different
# styles may have different numbers of available colors).
ax.set_xlim([-4, 8])
ax.set_ylim([-5, 6])
ax.set_aspect('equal', adjustable='box') # to plot circles as circles
return ax
示例4: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def plot(self, axis=None, show=False):
"""
Plot the coil location, using axis if given
The area of the coil is used to set the radius
"""
minor_radius = np.sqrt(self.area / np.pi)
import matplotlib.pyplot as plt
if axis is None:
fig = plt.figure()
axis = fig.add_subplot(111)
circle = plt.Circle((self.R, self.Z), minor_radius, color='b')
axis.add_artist(circle)
return axis
示例5: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def plot(self, show_axes=False):
import matplotlib.pyplot as plt
ax = plt.gca()
# change default range so that new disks will work
ax.axis("equal")
ax.set_xlim((-1.5, 1.5))
ax.set_ylim((-1.5, 1.5))
if not show_axes:
ax.set_axis_off()
disk1 = plt.Circle((0, 0), 1, color="k", fill=False)
ax.add_artist(disk1)
# The total area is used to gauge the disk radii. This is only meaningful for 2D
# manifolds, not for the circle. What we do instead is choose the total_area
# such that the sum of the disk radii equals pi.
total_area = numpy.pi ** 3 / len(self.weights)
plot_disks(plt, self.points, self.weights, total_area)
示例6: plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def plot(self, show_axes=False):
import matplotlib.pyplot as plt
ax = plt.gca()
# change default range so that new disks will work
plt.axis("equal")
ax.set_xlim((-1.5, 1.5))
ax.set_ylim((-1.5, 1.5))
if not show_axes:
ax.set_axis_off()
disk1 = plt.Circle((0, 0), 1, color="k", fill=False)
ax.add_artist(disk1)
plot_disks(plt, self.points, self.weights, numpy.pi)
return
示例7: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def __init__(self, pendulum_plant, refresh_period=(1.0/240),
name='PendulumDraw'):
super(PendulumDraw, self).__init__(pendulum_plant,
refresh_period, name)
l = self.plant.l
m = self.plant.m
self.mass_r = 0.05*np.sqrt(m) # distance to corner of bounding box
self.center_x = 0
self.center_y = 0
# initialize the patches to draw the pendulum
self.pole_line = plt.Line2D((self.center_x, 0), (self.center_y, l),
lw=2, c='r')
self.mass_circle = plt.Circle((0, l), self.mass_r, fc='y')
示例8: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def __init__(self,to_plot = True):
self.state = np.array([0,0])
self.observation_shape = np.shape(self.get_state())[0]
if to_plot:
plt.ion()
fig = plt.figure()
ax1 = fig.add_subplot(111,aspect='equal')
#ax1.axis('off')
plt.xlim([-0.5,5.5])
plt.ylim([-0.5,5.5])
self.g1 = ax1.add_artist(plt.Circle((self.state[0],self.state[1]),0.1,color='red'))
self.fig = fig
self.ax1 = ax1
self.fig.canvas.draw()
self.fig.canvas.flush_events()
示例9: _draw_maze_
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def _draw_maze_(maze_env, ax):
"""
The function to draw maze environment
Arguments:
maze_env: The maze environment configuration.
ax: The figure axis instance
"""
# draw maze walls
for wall in maze_env.walls:
line = plt.Line2D((wall.a.x, wall.b.x), (wall.a.y, wall.b.y), lw=1.5)
ax.add_line(line)
# draw start point
start_circle = plt.Circle((maze_env.agent.location.x, maze_env.agent.location.y),
radius=2.5, facecolor=(0.6, 1.0, 0.6), edgecolor='w')
ax.add_patch(start_circle)
# draw exit point
exit_circle = plt.Circle((maze_env.exit_point.x, maze_env.exit_point.y),
radius=2.5, facecolor=(1.0, 0.2, 0.0), edgecolor='w')
ax.add_patch(exit_circle)
示例10: main
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def main(show_animation):
cp = demo_cp
rx, ry, ryaw, rk = calcTrajectory(cp, 100)
t = 0.8
x_target, y_target = bezier(t, cp)
derivatives_cp = bezierDerivativesControlPoints(cp, 2)
point = bezier(t, cp)
dt = bezier(t, derivatives_cp[1])
ddt = bezier(t, derivatives_cp[2])
cu = curvature(dt[0], dt[1], ddt[0], ddt[1])
# Normalize derivative
dt /= np.linalg.norm(dt, 2)
tangent = np.array([point, point + dt])
normal = np.array([point, point + [- dt[1], dt[0]]])
# Radius of curvature
r = 1 / cu
curvature_center = point + np.array([- dt[1], dt[0]]) * r
circle = plt.Circle(tuple(curvature_center), r, color=(0, 0.8, 0.8), fill=False, linewidth=1)
if show_animation: # pragma: no cover
fig, ax = plt.subplots()
ax.plot(rx, ry, label="Bezier Path")
ax.plot(cp.T[0], cp.T[1], '--o', label="Control Points")
ax.plot(x_target, y_target, '--o', label="Target Point")
ax.plot(tangent[:, 0], tangent[:, 1], label="Tangent")
ax.plot(normal[:, 0], normal[:, 1], label="Normal")
ax.add_artist(circle)
ax.legend()
ax.axis("equal")
ax.grid(True)
plt.show()
示例11: legend_demo
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def legend_demo(ax):
x = np.linspace(0, 1, 30)
ax.plot(x, np.sin(2*np.pi*x), '-s', label='line')
c = plt.Circle((0.25, 0), radius=0.1, label='patch')
ax.add_patch(c)
ax.grid()
ax.legend()
ax.set_title('legend')
示例12: circle_and_text_demo
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def circle_and_text_demo(ax):
# Circles with colors from default color cycle
for i, color in enumerate(plt.rcParams['axes.color_cycle']):
xy = np.random.normal(size=2)
ax.add_patch(plt.Circle(xy, radius=0.3, color=color))
ax.axis('equal')
ax.margins(0)
# Text label centered on the axes.
ax.text(0.5, 0.5, 'hello world', ha='center', va='center',
transform=ax.transAxes)
ax.set_xlabel('x-label')
ax.set_ylabel('y-label')
ax.set_title('title')
示例13: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def __init__(self,drawing,**kwargs):
for k in ['coord','text','label']:
setattr(self,k,kwargs[k])
self.txt = plt.text(self.coord[0]+40,self.coord[1]+20,self.text,size=16)
self.dot = plt.Circle(self.coord,20)
drawing.ax.add_artist(self.dot)
low,high = drawing.crange
self.amp = high-low
self.low = low
示例14: my_plot
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def my_plot(fig, figures_i):
ax = fig.add_subplot(111, projection='3d')
X_i = X[figures_i, :, :]
U_i = U[figures_i, :, :]
K = X_i.shape[1]
ax.set_xlabel('X, east')
ax.set_ylabel('Y, north')
ax.set_zlabel('Z, up')
for k in range(K):
rx, ry, rz = X_i[1:4, k]
qw, qx, qy, qz = X_i[7:11, k]
CBI = np.array([
[1 - 2 * (qy ** 2 + qz ** 2), 2 * (qx * qy + qw * qz), 2 * (qx * qz - qw * qy)],
[2 * (qx * qy - qw * qz), 1 - 2 * (qx ** 2 + qz ** 2), 2 * (qy * qz + qw * qx)],
[2 * (qx * qz + qw * qy), 2 * (qy * qz - qw * qx), 1 - 2 * (qx ** 2 + qy ** 2)]
])
dx, dy, dz = np.dot(np.transpose(CBI), np.array([0., 0., 1.]))
Fx, Fy, Fz = np.dot(np.transpose(CBI), U_i[:, k])
# attitude vector
ax.quiver(rx, ry, rz, dx, dy, dz, length=attitude_scale, arrow_length_ratio=0.0, color='blue')
# thrust vector
ax.quiver(rx, ry, rz, -Fx, -Fy, -Fz, length=thrust_scale, arrow_length_ratio=0.0, color='red')
scale = X_i[3, 0]
ax.auto_scale_xyz([-scale / 2, scale / 2], [-scale / 2, scale / 2], [0, scale])
pad = plt.Circle((0, 0), 20, color='lightgray')
ax.add_patch(pad)
art3d.pathpatch_2d_to_3d(pad)
ax.set_title("Iteration " + str(figures_i))
ax.plot(X_i[1, :], X_i[2, :], X_i[3, :], color='lightgrey')
ax.set_aspect('equal')
示例15: height
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import Circle [as 别名]
def height(self):
shape = self.brush.style[1]
if isinstance(self.obj, plt.Circle):
return self.obj.radius * 2
elif isinstance(self.obj, plt.Rectangle):
return self.obj.get_height()
elif isinstance(self.obj, patches.FancyBboxPatch):
return self.obj.get_height() + 2*self.obj.get_boxstyle().pad
elif isinstance(self.obj, (plt.Polygon, patches.PathPatch)):
y = self.path[:,1]
return y.max() - y.min()
else:
raise