当前位置: 首页>>代码示例>>Python>>正文


Python Circle.set_facecolor方法代码示例

本文整理汇总了Python中matplotlib.patches.Circle.set_facecolor方法的典型用法代码示例。如果您正苦于以下问题:Python Circle.set_facecolor方法的具体用法?Python Circle.set_facecolor怎么用?Python Circle.set_facecolor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.patches.Circle的用法示例。


在下文中一共展示了Circle.set_facecolor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_breadcrumb

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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()
开发者ID:dwtj,项目名称:mars-rover,代码行数:12,代码来源:rover.py

示例2: circle

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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 )
开发者ID:otherview,项目名称:wlanlist,代码行数:14,代码来源:trataDados.py

示例3: scatter_plot

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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()
开发者ID:ee08b397,项目名称:hypy,代码行数:55,代码来源:tree.py

示例4: draw_ink

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [as 别名]
def draw_ink(ax, ink, node_size=0.1, penup_color='#0000FF',
             pendown_color='#00FF00', node_colors=None,
             show_order=False):
    current_stroke_id = 0
    for i in range(ink.shape[0]):
        # skip pen-up
        if ink[i,4] > 0:
            continue
            
        e = Circle(xy=(ink[i,0],ink[i,1]),radius=node_size, alpha=0.5)
        ax.add_artist(e)
        
        # pen-up/pen-down
        if i == 0 or ink[i-1,4] > 0:
            e.set_color(pendown_color)
            e.set_linewidth(5.0)
            current_stroke_id += 1

            if show_order:
                ax.text(ink[i,0]+node_size,ink[i,1],"[%d]"%current_stroke_id)

        elif i == ink.shape[0]-1 or ink[i+1,4] > 0:
            e.set_color(penup_color)
            e.set_linewidth(5.0)
            
        if node_colors is not None:
            e.set_facecolor(node_colors[i])
        
        # draw arrow
        if (i < ink.shape[0]-1 and
            ink[i,4] < 1 and
            ink[i+1,4] < 1):
            dx = ink[i+1,0]-ink[i,0]
            dy = ink[i+1,1]-ink[i,1]
            z = np.sqrt(dx*dx+dy*dy)
            dx = dx / max(z,1e-5)
            dy = dy / max(z,1e-5)
            if abs(dx) > 0 or abs(dy) > 0:
                ax.arrow(ink[i,0]-0.5*node_size*dx,
                         ink[i,1]-0.5*node_size*dy,
                         node_size*dx, node_size*dy,
                         fc="k", ec="k", alpha=0.5, width=0.007,
                         head_width=0.03, head_length=0.02,
                         length_includes_head=True)            

    ax.axis('equal')
开发者ID:sunsern,项目名称:uright-python,代码行数:48,代码来源:visualization.py

示例5: myCorrPlot

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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
开发者ID:mazieres,项目名称:corrplot,代码行数:45,代码来源:corrplot.py

示例6: circleFromRMS

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [as 别名]
def circleFromRMS(xy, rad):
	cir = Circle(xy, rad)
	cir.set_clip_box(ax.bbox)
	cir.set_alpha(0.2)
	cir.set_facecolor(tableau20[0])
	return cir
开发者ID:lmc0709,项目名称:filteringprocess,代码行数:8,代码来源:pillarPlot.py

示例7: im_phot

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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
开发者ID:abh13,项目名称:adampy,代码行数:66,代码来源:Calib_Photometry.py

示例8: add_danger

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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
开发者ID:dwtj,项目名称:mars-rover,代码行数:91,代码来源:rover.py

示例9: ArrayCalcAlongZ

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [as 别名]
    def ArrayCalcAlongZ(self,maxSDap,maxSDim,imSamp,wavel,fillFactor,path,fnamePNG,FourierFlag): 
        '''
        calculates the irradiance distribution along the optical axis of the instrument
        the 

        '''

        xxi        = num.linspace(-maxSDim,maxSDim,imSamp)
        zNum       = 0 
        
        for zz in self.zPos:
        
            zStep = zz
            ddq    = zStep
            print str(zStep)
            self.calcFarField(maxSDap,maxSDim,q,ddq,FourierFlag,wavel,fillFactor,imSamp)
            xp = self.xp
            yp = self.yp
            an = self.an
            nHoles = self.nHoles
            #self.calcNearField(maxSDap,maxSDim,q,ddq,FourierFlag,wavel,fillFactor,imSamp)
            IrradOn.append(self.Etot[imSamp/2.0,imSamp/2.0])
            zPlot.append(ddq)
                
# print hole locations and semi-diameters        
            if zz == 0:
                
                datHoles = num.zeros((len(self.xp),3))
                fid = open(fnameHoles,'w')
                cc = 0
                for ii in num.arange(len(nHoles)):
                    for jj in num.arange(nHoles[ii]):
                        datHoles[cc,0] = self.xp[cc]
                        datHoles[cc,1] = self.yp[cc]
                        datHoles[cc,2] = self.an[ii]
                        cc = cc + 1
                
                rr = 0    
                for rr in num.arange(len(datHoles)):
                    ss = 0
                    strVal = ''                 
                    for ss in num.arange(3):
                        strVal = strVal + '%12.6e '%(datHoles[rr,ss])
                    fid.write('%s\n'%(strVal))
                
                fid.close()
            
            # plot figures
            # aperture distribution    
            py.ion()
            py.figure(2,figsize=(12,4))
            py.clf()
            py.subplot(131)
            
            kk = 0
            for ii in num.arange(len(nHoles)):
                for jj in num.arange(nHoles[ii]):
                    py.plot(xp[kk], yp[kk])
                    ax   = py.gca()
                    xy   = [xp[kk],yp[kk]]
                    circ = Circle(xy, radius=an[ii])        # add circle plot 
                    ax.add_artist(circ)
                    circ.set_facecolor('none')
                    kk = kk + 1        
            
            py.xlabel(r'$\mathbf{X}(mm)$')
            py.ylabel(r'$\mathbf{Y}(mm)$')
            axis=py.gca()
            axis.axis('equal')
            py.ylim(-maxSDap,maxSDap)
            
            # profile
            #py.subplot(222)
            #py.plot(xxi,self.Etot[num.floor(imSamp/2.0),:]/num.max(self.Etot),'b')
            #py.plot(xxi,self.Etot[:,num.floor(imSamp/2.0)]/num.max(self.Etot),'k:')
            #py.title(r'$\mathbf{E}_{TOT}(\mathbf{x},0)$, 'r'$\mathbf{E}_{TOT}(0,\mathbf{y})$')
            #py.xlabel('position (mm)')
            #py.legend((r'$\mathbf{x}$',r'$\mathbf{y}$'),0)
            
            # total energy
            py.subplot(132)
            py.imshow(self.Etot,'bone')
            axis = py.gca()
            axis.axis('off')
            py.title(r'$\mathbf{E}_{TOT}$')
            
            # log of the total energy
            py.subplot(133)
            py.imshow(num.log10(self.Etot/num.max(self.Etot)),'bone')
            py.clim(-4,0)
            axis = py.gca()
            axis.axis('off')
            py.title(r'$log_{10}(\mathbf{E}_{TOT})$')
            
            figname = path + fnamePNG + str(zNum+1) + '.png'
            py.savefig(figname)
            zNum = zNum + 1
        
        # plot the on-axis irradiance as calculated by the full diffraction treatment
        #py.figure(1)
#.........这里部分代码省略.........
开发者ID:yybar,项目名称:PhotonSieve,代码行数:103,代码来源:PhotonSieveDiffract.py

示例10: ZEMAXuserdefinedApertures

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [as 别名]
    def ZEMAXuserdefinedApertures(self,maxSDap,edgeD,Nrings,segPlotFlag):
        '''Generate the UDA files needed for ZEMAX to model a segmented photonsieve telescope.  
        This is only set-up for 2 rings right now (18 segments).  
        The hexagon segmented apertures are plotted if segPlotFlag == 1
        '''
        nHoles  = self.nHoles                   # nHoles vector elements are number of 
                                                # holes for each radial zone
        an      = self.an                       # an vector contains hole semi-diameter   
        xp      = self.xp                       # x locations of holes  
        yp      = self.yp                       # y locations of holes  
        pi      = num.arccos(-1)
        Nsegs   = 3*Nrings*(Nrings+1)           # number of hexgonal segments as function of rings  
        segDiam = 4.0*(maxSDap+edgeD)/5.0/num.sqrt(3)   # segment point-point diameter assuming 3rings
        segSep  = num.sqrt(3)/2.0*segDiam+edgeD
        xSeg    = num.zeros((18,1))             # segment x locations
        ySeg    = num.empty((18,1))             # segment y locations
        xPlotQ  = num.empty((0,))
        yPlotQ  = num.empty((0,))
        

        fidLocSeg = open('SegPosTable.txt','w')
# locate the positions of the segment centers        
        for segNum in num.arange(Nsegs):  
            if segNum <= 5:                                         # first ring
                xSeg[segNum] = segSep*num.sin(pi*segNum/3.0)
                ySeg[segNum] = segSep*num.cos(pi*segNum/3.0)
            elif segNum > 5 and segNum < 12:                        # second ring
                xSeg[segNum] = 2.0*segSep*num.sin(pi*segNum/3.0)
                ySeg[segNum] = 2.0*segSep*num.cos(pi*segNum/3.0)
            elif segNum > 11 & segNum < 19: 	                    # third ring			
                xSeg[segNum] = 2.0*segSep*num.sin(pi*segNum/3.0+pi/6.0)*num.cos(pi/6.0)
                ySeg[segNum] = 2.0*segSep*num.cos(pi*segNum/3.0+pi/6.0)*num.cos(pi/6.0)

# print the segment center locations to the file SegPosTable.txt
            strLoc = '%6.4f'%(xSeg[segNum]) + ' ' + '%6.4f'%(ySeg[segNum])   
            fidLocSeg.write('%s \n'%(strLoc))    
# choose plotting segments                  
            self.chooseSegment(segNum,segDiam,0,0,0,segPlotFlag) # determine location of holes in segment
            py.ion()
            py.figure(self.figSegNum,figsize=(11,11))
            py.plot(self.xPlotQ1 + xSeg[segNum],self.yPlotQ1 + ySeg[segNum],'k')    
            py.plot(self.xPlotQ2 + xSeg[segNum],self.yPlotQ2 + ySeg[segNum],'k')    
            py.plot(self.xPlotQ3 + xSeg[segNum],self.yPlotQ3 + ySeg[segNum],'k')    
            py.plot(self.xPlotQ4 + xSeg[segNum],self.yPlotQ4 + ySeg[segNum],'k') 
           
            fileStr="PrimSeg" + str(segNum+1) + ".UDA"
            fid    = open(fileStr,'w')                                          # generate a file handle for the given segment
            strVal = 'POL ' + '%6.4f '%(xSeg[segNum]) + '%6.4f '%(ySeg[segNum]) + \
                     ' ' + '%6.4f '%(segDiam/2.0) + '%i'%(6)
            fid.write('%s \n'%(strVal))                                         # write the segment 
        
            kk = 0
            for ii in num.arange(len(nHoles)):
                for jj in num.arange(nHoles[ii]):
                    dx = xp[kk] - xSeg[segNum]
                    dy = yp[kk] - ySeg[segNum]
                    self.chooseSegment(segNum,segDiam,dx,dy,an[ii],0)           # determine location of holes in segment
                    if self.segFlag == 1:                                       # if within segment
                        strVal = 'CIR ' + '%6.4f '%(xp[kk]) + '%6.4f '%(yp[kk]) + \
                                 '%6.4f'%(an[ii])
                        fid.write('%s \n'%(strVal))
                        py.plot(xp[kk],yp[kk])
                        ax   = py.gca()
                        xy   = [self.xp[kk],self.yp[kk]]
                        circ = Circle(xy, radius=self.an[ii])      # add circle plot 
                        ax.add_artist(circ)
                        circ.set_facecolor('none')     
                    kk = kk + 1                                    # update hole counter
            fid.close()                                            # close the .UDA file
       
        fidLocSeg.close()                                              # close the segment center location txt file        
        self.xSeg   = xSeg                                             # x location of segment
        self.ySeg   = ySeg                                             # y location of segment 
        self.xPlotQ = xPlotQ
        self.yPlotQ = yPlotQ

        return self
开发者ID:yybar,项目名称:PhotonSieve,代码行数:79,代码来源:PhotonSieveDiffract.py

示例11: scatter_plot

# 需要导入模块: from matplotlib.patches import Circle [as 别名]
# 或者: from matplotlib.patches.Circle import set_facecolor [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()
开发者ID:BritneyMuller,项目名称:pyh3,代码行数:73,代码来源:tree.py


注:本文中的matplotlib.patches.Circle.set_facecolor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。