本文整理汇总了Python中matplotlib.patches.Circle.set_edgecolor方法的典型用法代码示例。如果您正苦于以下问题:Python Circle.set_edgecolor方法的具体用法?Python Circle.set_edgecolor怎么用?Python Circle.set_edgecolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.patches.Circle
的用法示例。
在下文中一共展示了Circle.set_edgecolor方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_breadcrumb
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
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()
示例2: circle
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
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 )
示例3: scatter_plot
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
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()
示例4: myCorrPlot
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
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
示例5: _add_patches
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def _add_patches(self, df, method, fill, ax, diagonal=True):
width, height = df.shape
patches = []
colors = []
for x in range(width):
for y in range(height):
if fill == 'lower' and x > y:
continue
elif fill == 'upper' and x < y:
continue
if diagonal is False and x == y:
continue
datum = (df.ix[x, y] + 1.) / 2.
d = df.ix[x, y]
d_abs = np.abs(d)
#c = self.pvalues[x, y]
rotate = -45 if d > 0 else +45
#cmap = self.poscm if d >= 0 else self.negcm
if method in ['ellipse', 'square', 'rectangle', 'color']:
if method == 'ellipse':
func = Ellipse
patch = func((x, y), width=1 * self.shrink,
height=(self.shrink - d_abs * self.shrink), angle=rotate)
else:
func = Rectangle
w = h = d_abs * self.shrink
# FIXME shring must be <=1
offset = (1 - w) / 2.
if method == 'color':
w = 1
h = 1
offset = 0
patch = func((x + offset - .5, y + offset - .5), width=w,
height=h, angle=0)
if self.edgecolor:
patch.set_edgecolor(self.edgecolor)
# patch.set_facecolor(cmap(d_abs))
colors.append(datum)
if d_abs > 0.05:
patch.set_linestyle('dotted')
# ax.add_artist(patch)
patches.append(patch)
# FIXME edgecolor is always printed
elif method == 'circle':
patch = Circle((x, y), radius=d_abs * self.shrink / 2.)
if self.edgecolor:
patch.set_edgecolor(self.edgecolor)
# patch.set_facecolor(cmap(d_abs))
colors.append(datum)
if d_abs > 0.05:
patch.set_linestyle('dotted')
# ax.add_artist(patch)
patches.append(patch)
elif method in ['number', 'text']:
if d < 0:
edgecolor = self.cm(-1.0)
elif d >= 0:
edgecolor = self.cm(1.0)
d_str = "{:.2f}".format(d).replace(
"0.", ".").replace(".00", "")
ax.text(x, y, d_str, color=edgecolor,
fontsize=self.fontsize, horizontalalignment='center',
weight='bold', alpha=max(0.5, d_abs),
withdash=False)
elif method == 'pie':
S = 360 * d_abs
patch = [
Wedge((x, y), 1 * self.shrink / 2., -90, S - 90),
Wedge((x, y), 1 * self.shrink / 2., S - 90, 360 - 90),
]
# patch[0].set_facecolor(cmap(d_abs))
# patch[1].set_facecolor('white')
colors.append(datum)
colors.append(0.5)
if self.edgecolor:
patch[0].set_edgecolor(self.edgecolor)
patch[1].set_edgecolor(self.edgecolor)
# ax.add_artist(patch[0])
# ax.add_artist(patch[1])
patches.append(patch[0])
patches.append(patch[1])
else:
raise ValueError(
'Method for the symbols is not known. Use e.g, square, circle')
if self.binarise_color:
colors = [1 if color > 0.5 else -1 for color in colors]
if len(patches):
col1 = PatchCollection(
patches, array=np.array(colors), cmap=self.cm)
ax.add_collection(col1)
self.collection = col1
示例6: im_phot
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def im_phot(directory,gain,im_file,aperture):
""" Perform photometry on the image """
# Read in fits image file and create array with wcs coordinates
os.chdir(directory)
hdulist = fits.open(im_file)
w = WCS(im_file)
data = hdulist[0].data
data[np.isnan(data)] = 0
hdulist.close()
# Calculate center point of image (RA, Dec) if not input by user
targetra, targetdec = w.all_pix2world(len(data[:,0])/2,len(data[0,:])/2,0)
# Use SEP for background subtraction and source detection
datasw = data.byteswap().newbyteorder().astype('float64')
bkg = sep.Background(datasw)
data_bgs = data - bkg
data_bgs[data_bgs < 0] = 0
mean = np.mean(data_bgs)
median = np.median(data_bgs)
std = bkg.globalrms
objects = sep.extract(data_bgs,3,err=bkg.globalrms)
objra, objdec = w.all_pix2world(objects['x'],objects['y'],0)
# Find dummy magnitudes using aperture photometry and plot images
fig, ax = plt.subplots()
image = plt.imshow(data_bgs,cmap='gray',vmin=(mean-3*std),
vmax=(mean+3*std),origin='lower')
sepmag = []
sepmagerr = []
ra = []
dec = []
xpixel = []
ypixel = []
for i in range(len(objects)):
# Perform circular aperture photometry
flux,fluxerr,flag = sep.sum_circle(data_bgs,objects['x'][i],
objects['y'][i],aperture,err=std,gain=gain)
mag = -2.5*np.log10(flux)
maglimit1 = -2.5*np.log10((flux+fluxerr))
maglimit2 = -2.5*np.log10((flux-fluxerr))
magerr1 = np.abs(mag-maglimit1)
magerr2 = np.abs(mag-maglimit2)
magerr = (magerr1+magerr2)/2
# Save object properties to arrays
sepmag.append(mag)
sepmagerr.append(magerr)
ra.append(objra[i])
dec.append(objdec[i])
xpixel.append(objects['x'][i])
ypixel.append(objects['y'][i])
# Plot the detections on the image
out = Circle(xy=(objects['x'][i],objects['y'][i]),radius=aperture)
out.set_facecolor('none')
out.set_edgecolor('red')
ax.add_artist(out)
plt.savefig(directory+'detections.png')
return targetra,targetdec,sepmag,sepmagerr,ra,dec,xpixel,ypixel
示例7: add_danger
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def add_danger(self, danger_id):
""" Appends a new danger to the appropriate list of `env`, and updates
the `env` view. The position at which the danger is placed is computed
based on the rover's location and direction, but also where on the
robot that particular danger-detection sensor is located. """
"""if danger_id == left_bumper:
elif danger_id == right_bumper:
elif danger_id == left_and_right_bumper:
elif danger_id == front_left_cliff:
elif danger_id == front_right_cliff:
elif danger_id == left_cliff:
elif danger_id == right_cliff:
elif danger_id == white_tape_front_left:
elif danger_id == white_tape_front_right:
elif danger_id == white_tape_left:
elif danger_id == white_tape_right:
elif danger_id == left_wheel:
elif danger_id == right_wheel:
elif danger_id == middle_wheel:
else:
raise NotImplementedError()
"""
# Find the danger location using `danger_angle` and `danger_distance`
# TODO: maybe later
# danger_loc = conv_radial(self, danger_theta, danger_r)
# Plot
if (1 <= danger_id <= 3): # Bumper range in OIStopID
""" Adds a bump """
c = Circle(self._loc, radius = 6.25)
c.set_facecolor('0.65') # grey
c.set_edgecolor('black')
c.set_zorder(zorders['bumps'])
c.set_fill(True)
self.view.add_artist(c)
self.bumps.append(c)
self.draw()
elif (4 <= danger_id <= 7): # Cliff range in OIStopID
""" Adds a cliff """
c = Circle(self._loc, radius = 6.25)
c.set_facecolor('0.65') # grey
c.set_edgecolor('black')
c.set_zorder(zorders['cliffs'])
c.set_fill(True)
self.view.add_artist(c)
self.cliffs.append(c)
self.draw()
elif (12 <= danger_id <= 14): # Drop range in OIStopID
""" Adds a drop """
c = Circle(self._loc, radius = 6.25)
c.set_facecolor('0.65') # grey
c.set_edgecolor('black')
c.set_zorder(zorders['drops'])
c.set_fill(True)
self.view.add_artist(c)
self.drops.append(c)
self.draw()
elif (8 <= danger_id <= 11): # White tape range in OIStopID
""" Adds tape """
c = Circle(self._loc, radius = 6.25)
c.set_facecolor('0.65') # grey
c.set_edgecolor('black')
c.set_zorder(zorders['tape'])
c.set_fill(True)
self.view.add_artist(c)
self.tape.append(c)
self.draw()
else:
raise NotImplementedError()
# The following is the temporary workaround:
sys.stderr.write("danger found: " + str(danger_id)) # TODO: check to see if enum strig is a thing
示例8: gen_png
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def gen_png(*args):
if len(args) == 1:
if len(args[0]) == 4:
res = args[0][0]
f_name = args[0][1]
extension = args[0][2]
header_lines = args[0][3]
elif len(args) == 4:
res = args[0]
f_name = args[1]
extension = args[2]
header_lines = args[3]
else:
print "Wrong number or type of arguments, aborting"
return (-1)
data = np.loadtxt(f_name+extension, skiprows=header_lines)
header = np.genfromtxt(f_name+extension, max_rows=4)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
global t
t += header[-1]
dt = header[-1]
to_delete = []
for i in range(0, data.shape[0]):
if (data[i,1] < 0 and data[i,0] >0):
to_delete.append(i)
data = np.delete(data, to_delete, axis=0)
rho = data[::res,-2]
norm_rho = np.zeros(rho.shape)
# print np.amin(rho), np.amax(rho)
for i in range(0, np.shape(rho)[0]):
norm_rho[i] = (rho[i]-np.amin(rho))/(np.amax(rho)-np.amin(rho))
# print np.amin(rho), np.amax(rho), rho
# print np.amin(norm_rho), np.amax(norm_rho), norm_rho
norm = LogNorm(vmin=np.amin(rho), vmax=np.amax(rho), clip=False)
radius = np.amax(data[::res,2])
circle1 = Circle((0,0), radius)
circle1.set_fill(True)
circle1.set_edgecolor('red')
circle1.set_fc('grey')
circle1.set_alpha(0.5)
ax.add_patch(circle1)
art3d.pathpatch_2d_to_3d(circle1, z=0, zdir="y")
s = ax.scatter(data[::res,0], data[::res,1], data[::res,2], norm=norm, cmap='hot', c=rho, marker='.')
ax.text2D(0.05, 0.95, '{} myr; {} myr'.format(t,dt), transform=ax.transAxes)
ax.set_ylim(ax.get_xlim())
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
fig.colorbar(s, shrink=0.5, aspect=5)
# circle2 = Circle((0,0), radius)
# circle2.set_fill(False)
# circle2.set_edgecolor('red')
# ax.add_patch(circle2)
# art3d.pathpatch_2d_to_3d(circle2, z=0, zdir="x")
plt.savefig(f_name+'.png', dpi=300, papertype='a4')
#plt.show()
plt.close(fig)
return (f_name, 0)
示例9: scatter_plot
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def scatter_plot(self, equators=True, tagging=True, depth_cap=None, node_coloring=None):
"""
Plot the tree with nodes and edges, optionally equators and tagging nodes with node numbers.
The tree is traversed in a breath-first-search.
Note:
- To distinct each generations, a color plate of ["blue", "red", "yellow", "green", "black"]
is used repeatedly.
- The X, Y, Z axises have been labelled.
- When the number of nodes is large and the tree is bushy, it's advised disabling tagging for
better user experience.
:param bool equators: whether to draw the 3D equators, default True
:param bool tagging: whether to tag nodes with node numbers, default True
:param int depth_cap: a filter for rendering the first N generations, default tree height
:param dict node_coloring: an optional map from node_id : color, to color individual nodes
"""
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.node_id].coord.x]
ys = [self.nodes[self.root.node_id].coord.y]
zs = [self.nodes[self.root.node_id].coord.z]
plot_color_board = ["blue", "red", "yellow", "green", "black"]
font0 = FontProperties()
font0.set_size(8)
current_generation = deque([self.root.node_id])
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.node_id)
if self.nodes[n].depth <= depth_cap:
xe = [self.nodes[n].coord.x, self.nodes[child.node_id].coord.x]
ye = [self.nodes[n].coord.y, self.nodes[child.node_id].coord.y]
ze = [self.nodes[n].coord.z, self.nodes[child.node_id].coord.z]
if node_coloring:
ax.plot(xe, ye, ze, node_coloring.get(n, 'black'))
else:
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.node_id].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()
示例10: _add_patches
# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_edgecolor [as 别名]
def _add_patches(self, df, method, fill, ax, diagonal=True):
width, height = df.shape
labels = (df.columns)
patches = []
colors = []
for x in xrange(width):
for y in xrange(height):
if fill == 'lower' and x > y:
continue
elif fill == 'upper' and x < y:
continue
if diagonal is False and x==y:
continue
datum = (df.ix[x, y] +1.)/2.
d = df.ix[x, y]
d_abs = np.abs(d)
#c = self.pvalues[x, y]
rotate = -45 if d > 0 else +45
#cmap = self.poscm if d >= 0 else self.negcm
if method in ['ellipse', 'square', 'rectangle', 'color']:
if method == 'ellipse':
func = Ellipse
patch = func((x, y), width=1 * self.shrink,
height=(self.shrink - d_abs*self.shrink), angle=rotate)
else:
func = Rectangle
w = h = d_abs * self.shrink
#FIXME shring must be <=1
offset = (1-w)/2.
if method == 'color':
w = 1
h = 1
offset = 0
patch = func((x + offset-.5, y + offset-.5), width=w,
height=h, angle=0)
if self.edgecolor:
patch.set_edgecolor(self.edgecolor)
#patch.set_facecolor(cmap(d_abs))
colors.append(datum)
if d_abs > 0.05:
patch.set_linestyle('dotted')
#ax.add_artist(patch)
patches.append(patch)
#FIXME edgecolor is always printed
elif method=='circle':
patch = Circle((x, y), radius=d_abs*self.shrink/2.)
if self.edgecolor:
patch.set_edgecolor(self.edgecolor)
#patch.set_facecolor(cmap(d_abs))
colors.append(datum)
if d_abs > 0.05:
patch.set_linestyle('dotted')
#ax.add_artist(patch)
patches.append(patch)
elif method in ['number', 'text']:
from easydev import precision
if d<0:
edgecolor = 'red'
elif d>=0:
edgecolor = 'blue'
ax.text(x,y, precision(d, 2), color=edgecolor,
fontsize=self.fontsize, horizontalalignment='center',
weight='bold', alpha=d_abs,
withdash=False)
elif method == 'pie':
S = 360 * d_abs
patch = [
Wedge((x,y), 1*self.shrink/2., -90, S-90),
Wedge((x,y), 1*self.shrink/2., S-90, 360-90),
]
#patch[0].set_facecolor(cmap(d_abs))
#patch[1].set_facecolor('white')
colors.append(datum)
colors.append(0.5)
if self.edgecolor:
patch[0].set_edgecolor(self.edgecolor)
patch[1].set_edgecolor(self.edgecolor)
#ax.add_artist(patch[0])
#ax.add_artist(patch[1])
patches.append(patch[0])
patches.append(patch[1])
if len(patches):
col1 = PatchCollection(patches, array=np.array(colors), cmap=self.cm)
ax.add_collection(col1)
self.collection = col1