• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python networkx.draw_networkx_labels函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中networkx.draw_networkx_labels函数的典型用法代码示例。如果您正苦于以下问题:Python draw_networkx_labels函数的具体用法?Python draw_networkx_labels怎么用?Python draw_networkx_labels使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: drawgraph

def drawgraph(graph,fixed):
	pos=nx.spring_layout(graph)
	nx.draw_networkx_nodes(graph,pos,with_labels=True,node_size=100)
	nx.draw_networkx_nodes(graph,pos,with_labels=True,nodelist=fixed,node_size=100,node_color="yellow")
	nx.draw_networkx_edges(graph,pos,with_labels=True,width=0.3)
	nx.draw_networkx_labels(graph,pos,fontsize=10)
	plt.show()
开发者ID:girolamogiudice,项目名称:nbea,代码行数:7,代码来源:filterlib6.py


示例2: draw_network

    def draw_network(self, m=2, pos=None):
        edgelist = []
        probdict = {}
        nodesizes = {}
        position = {}
        observations = {}
        for i, node in enumerate(self.nodes[::-1]):
            l, u = node.ppf(.1), node.ppf(.9)
            c, w = .5 * (l + u), .5 * (u - l)
            edgelist += [(node.name, x.name) for x in node.children]
            probdict[node.name] = c
            nodesizes[node.name] = 100 + 5000 * w
            position[node.name] = (i / m, i % m) if pos is None else pos[node.name]
            observations[node.name] = '%.2f+/-%.2f' % (c, w)

        G = nx.DiGraph()
        G.add_edges_from(edgelist)
        values = [probdict.get(node) for node in G.nodes()]
        sizes = [nodesizes.get(node) for node in G.nodes()]

        plt.figure(figsize=(16,8))
        nx.draw_networkx_nodes(G, position, node_size=sizes, cmap=plt.get_cmap('Blues'), node_color=values, vmin=-0.1, vmax=1)
        nx.draw_networkx_labels(G, position, {x: x for x in G.nodes()}, font_size=12, font_color='r')
        nx.draw_networkx_labels(G, {key: (x[0] , x[1]+.3) for key, x in position.iteritems()}, observations,
                                font_size=12, font_color='k')
        nx.draw_networkx_edges(G, position, edgelist=edgelist, edge_color='r', arrows=True, alpha=0.5)
        # plt.xlim((-.15,.9))
        plt.show()
开发者ID:raycoledai,项目名称:diagnostic_test,代码行数:28,代码来源:prob_model.py


示例3: test_labels_and_colors

 def test_labels_and_colors(self):
     G = nx.cubical_graph()
     pos = nx.spring_layout(G)  # positions for all nodes
     # nodes
     nx.draw_networkx_nodes(G, pos,
                            nodelist=[0, 1, 2, 3],
                            node_color='r',
                            node_size=500,
                            alpha=0.8)
     nx.draw_networkx_nodes(G, pos,
                            nodelist=[4, 5, 6, 7],
                            node_color='b',
                            node_size=500,
                            alpha=0.8)
     # edges
     nx.draw_networkx_edges(G, pos, width=1.0, alpha=0.5)
     nx.draw_networkx_edges(G, pos,
                            edgelist=[(0, 1), (1, 2), (2, 3), (3, 0)],
                            width=8, alpha=0.5, edge_color='r')
     nx.draw_networkx_edges(G, pos,
                            edgelist=[(4, 5), (5, 6), (6, 7), (7, 4)],
                            width=8, alpha=0.5, edge_color='b')
     # some math labels
     labels = {}
     labels[0] = r'$a$'
     labels[1] = r'$b$'
     labels[2] = r'$c$'
     labels[3] = r'$d$'
     labels[4] = r'$\alpha$'
     labels[5] = r'$\beta$'
     labels[6] = r'$\gamma$'
     labels[7] = r'$\delta$'
     nx.draw_networkx_labels(G, pos, labels, font_size=16)
     plt.show()
开发者ID:ProgVal,项目名称:networkx,代码行数:34,代码来源:test_pylab.py


示例4: plotsolution

def plotsolution(numnodes,coordinates,routes):
   plt.ion() # interactive mode on
   G=nx.Graph()
   
   nodes = range(1,numnodes+1)
   nodedict = {}
   for i in nodes:
     nodedict[i] = i
   
   nodecolorlist = ['b' for i in nodes]
   nodecolorlist[0] = 'r'
     
   # nodes  
   nx.draw_networkx_nodes(G, coordinates, node_color=nodecolorlist, nodelist=nodes)
   # labels
   nx.draw_networkx_labels(G,coordinates,font_size=9,font_family='sans-serif',labels = nodedict)
   
   edgelist = defaultdict(list)
   
   colors = ['Navy','PaleVioletRed','Yellow','Darkorange','Chartreuse','CadetBlue','Tomato','Turquoise','Teal','Violet','Silver','LightSeaGreen','DeepPink', 'FireBrick','Blue','Green']
   
   for i in (routes):
     edge1 = 1
     for j in routes[i][1:]:
       edge2 = j
       edgelist[i].append((edge1,edge2))
       edge1 = edge2
       nx.draw_networkx_edges(G,coordinates,edgelist=edgelist[i],
                        width=6,alpha=0.5,edge_color=colors[i]) #,style='dashed'
   
   plt.savefig("path.png")

   plt.show()
开发者ID:adity,项目名称:Vehicle-Routing,代码行数:33,代码来源:plotsolution.py


示例5: plot

def plot(CG):
    """
    Plot the call graph using matplotlib
    For larger graphs, this should not be used, as it is very slow
    and probably you can not see anything on it.

    :param CG: A networkx graph to plot
    """
    pos = nx.spring_layout(CG)

    internal = []
    external = []

    for n in CG.node:
        if isinstance(n, ExternalMethod):
            external.append(n)
        else:
            internal.append(n)

    nx.draw_networkx_nodes(CG, pos=pos, node_color='r', nodelist=internal)
    nx.draw_networkx_nodes(CG, pos=pos, node_color='b', nodelist=external)
    nx.draw_networkx_edges(CG, pos, arrow=True)
    nx.draw_networkx_labels(CG, pos=pos, labels={x: "{} {}".format(x.get_class_name(), x.get_name()) for x in CG.edge})
    plt.draw()
    plt.show()
开发者ID:shuxin,项目名称:androguard,代码行数:25,代码来源:androcg.py


示例6: draw_graphs

def draw_graphs(G,edge_pro_dict,Gmp,Ggp,Gadr,Gabm):
  plt.figure(1)
  pos=nx.spring_layout(G) # positions for all nodes
  nx.draw_networkx_nodes(G,pos,noG=800)
  nx.draw_networkx_edges(G,pos)
  nx.draw_networkx_labels(G,pos,font_size=10,font_family='sans-serif')
  nx.draw_networkx_edge_labels(G,pos,edge_labels=edge_pro_dict)

  plt.figure(2)
  nx.draw_networkx_nodes(Gmp,pos,noG=800)
  nx.draw_networkx_edges(Gmp,pos)
  nx.draw_networkx_labels(Gmp,pos,font_size=10,font_family='sans-serif')

  plt.figure(3)
  nx.draw_networkx_nodes(Ggp,pos,noG=800)
  nx.draw_networkx_edges(Ggp,pos)
  nx.draw_networkx_labels(Ggp,pos,font_size=10,font_family='sans-serif')

  plt.figure(4)
  nx.draw_networkx_nodes(Gadr,pos,noG=800)
  nx.draw_networkx_edges(Gadr,pos)
  nx.draw_networkx_labels(Gadr,pos,font_size=10,font_family='sans-serif')

  plt.figure(5)
  nx.draw_networkx_nodes(Gabm,pos,noG=800)
  nx.draw_networkx_edges(Gabm,pos)
  nx.draw_networkx_labels(Gabm,pos,font_size=10,font_family='sans-serif')

  plt.show()
开发者ID:sun9700,项目名称:GA4UG,代码行数:29,代码来源:draw_graph_basic.py


示例7: draw

  def draw(self, layout_type='spring_layout'):
      '''
      Draw the graph
      
      layout_type = The type of layout algorithm (Default = 'spring_layout')
      '''
  
      import matplotlib.pyplot as plt
      
      try:
          pos = getattr(nx, layout_type)(self.G)
      except:
          raise Exception('layout_type of %s is not valid' % layout_type)
 
  
      nx.draw_networkx_nodes(self.G,pos,
                             nodelist=self.species,
                             node_color=self.options['species']['color'],
                             node_size=self.options['species']['size'],
                             alpha=self.options['species']['alpha'])
      nx.draw_networkx_edges(self.G, pos, edgelist=self.product_edges)
      nx.draw_networkx_edges(self.G, pos, edgelist=self.reactant_edges, arrows=False)
      nx.draw_networkx_edges(self.G, pos, edgelist=self.modifier_edges, style='dashed')
      
      labels = {}
      for n in self.G.nodes():
          if n in self.species:
              labels[n] = n
      nx.draw_networkx_labels(self.G,pos,labels,font_size=self.options['species']['label_size'])
      plt.axis('off')
      plt.show()
开发者ID:stanleygu,项目名称:ipython-notebook-tools,代码行数:31,代码来源:_graph.py


示例8: report_ctg

def report_ctg(ctg, filename):
    """
    Reports Clustered Task Graph in the Console and draws CTG in file
    :param ctg: clustered task graph
    :param filename: drawing file name
    :return: None
    """
    print "==========================================="
    print "      REPORTING CLUSTERED TASK GRAPH"
    print "==========================================="
    cluster_task_list_dict = {}
    cluster_weight_dict = {}
    for node in ctg.nodes():
        print ("\tCLUSTER #: "+str(node)+"\tTASKS:"+str(ctg.node[node]['TaskList'])+"\tUTILIZATION: " +
               str(ctg.node[node]['Utilization']))
        cluster_task_list_dict[node] = ctg.node[node]['TaskList']
    for edge in ctg.edges():
        print ("\tEDGE #: "+str(edge)+"\tWEIGHT: "+str(ctg.edge[edge[0]][edge[1]]['Weight']))
        cluster_weight_dict[edge] = ctg.edge[edge[0]][edge[1]]['Weight']
    print ("PREPARING GRAPH DRAWINGS...")
    pos = networkx.shell_layout(ctg)
    networkx.draw_networkx_nodes(ctg, pos, node_size=2200, node_color='#FAA5A5')
    networkx.draw_networkx_edges(ctg, pos)
    networkx.draw_networkx_edge_labels(ctg, pos, edge_labels=cluster_weight_dict)
    networkx.draw_networkx_labels(ctg, pos, labels=cluster_task_list_dict)
    plt.savefig("GraphDrawings/"+filename)
    plt.clf()
    print ("\033[35m* VIZ::\033[0mGRAPH DRAWINGS DONE, CHECK \"GraphDrawings/"+filename+"\"")
    return None
开发者ID:siavooshpayandehazad,项目名称:SoCDep2,代码行数:29,代码来源:Clustering_Reports.py


示例9: draw_graph

def draw_graph(edges, up_words, down_words, node_size, node_color='blue', node_alpha=0.3,
               node_text_size=12, edge_color='blue', edge_alpha=0.3, edge_tickness=2,
               text_font='sans-serif', file_name="graph"):
    plt.clf()
    g = nx.Graph()

    for edge in edges:
        g.add_edge(edge[0], edge[1])

    graph_pos = nx.shell_layout(g)  # layout for the network

    # up_words = map(lambda x: translate_node(x), up_words)
    # down_words = map(lambda x: x + "(" + translate_node(x) + ")", down_words)  # add translated nodes to graph

    try:
        nx.draw_networkx_nodes(g, graph_pos, nodelist=up_words, node_size=node_size,
                               alpha=node_alpha, node_color='red')
        nx.draw_networkx_nodes(g, graph_pos, nodelist=down_words, node_size=node_size,
                               alpha=node_alpha, node_color=node_color)
        nx.draw_networkx_edges(g, graph_pos, width=edge_tickness,
                               alpha=edge_alpha, edge_color=edge_color)
        nx.draw_networkx_labels(g, graph_pos, font_size=node_text_size,
                                font_family=text_font)
    except:
        print 'draw error'

    plt.savefig(result_path + file_name, format="PNG")
开发者ID:runninghack,项目名称:draw_detected_graph,代码行数:27,代码来源:plot_single.py


示例10: plot_dg

def plot_dg(dg):
    plt.figure()
#    pos = networkx.spring_layout(dg)
    pos = networkx.pygraphviz_layout(dg,'dot')
    networkx.draw_networkx_labels(dg,pos)
    networkx.draw(dg,pos,arrows=True)
    plt.show()
开发者ID:heiko114514,项目名称:popupcad,代码行数:7,代码来源:design_file_connections.py


示例11: graph_terms_to_topics

def graph_terms_to_topics(lda, num_terms=num_top):
    #topic names: select appropriate "t" based on number of topics
    #Use line below for num_top = 15.
    t = ['0','1', '2','3','4','5','6','7','8','9','10','11','12','13','14']
    #Use line below for num_top = 25.
    #t = ['0','1', '2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24']
    #Use line below for num_top = 35.
    #t = ['0','1', '2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34']       
    #Use line below for num_top = 45.
    #t = ['0','1', '2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44']       
    
#Create a network graph and size it.
    G = nx.Graph()
    plt.figure(figsize=(16,16))
    # generate the edges
    for i in range(0, lda.num_topics):
        topicLabel = t[i]
        terms = [term for term, val in lda.show_topic(i, num_terms+1)]
        for term in terms:
            G.add_edge(topicLabel, term, edge_color='red')
    
    pos = nx.spring_layout(G) # positions for all nodes
    
    #Plot topic labels and terms labels separately to have different colours
    g = G.subgraph([topic for topic, _ in pos.items() if topic in t])
    nx.draw_networkx_labels(g, pos, font_size=20, font_color='r')
    #If network graph is difficult to read, don't plot ngrams titles.
    #g = G.subgraph([term for term, _ in pos.items() if str(term) not in t])
    #nx.draw_networkx_labels(g, pos, font_size=12, font_color='orange')
    #Plot edges
    nx.draw_networkx_edges(G, pos, edgelist=G.edges(), alpha=0.3)
    #Having trouble saving graph to file automatically; below code not working. Must manually save.
    plt.axis('off')
    plt.show(block=False)
    plt.savefig('/Users/Marcia/OneDrive/UNCC General/DSBA_6880/Misc_Analysis_Files/TopicNetwork'+num+'.png', bbox_inches='tight')
开发者ID:VectorAnalytics,项目名称:Patent_Analysis_Python,代码行数:35,代码来源:TopicModelingW_Vis.py


示例12: plot_co_x

def plot_co_x(cox, start, end, size = (20,20), title = '', weighted=False, weight_threshold=10):

        """ Plotting function for keyword graphs

        Parameters
        --------------------
        cox: the coword networkx graph; assumes that nodes have attribute 'topic'
        start: start year
        end: end year
        """

        plt.figure(figsize=size)
        plt.title(title +' %s - %s'%(start,end), fontsize=18)
        if weighted:
            elarge=[(u,v) for (u,v,d) in cox.edges(data=True) if d['weight'] >weight_threshold]
            esmall=[(u,v) for (u,v,d) in cox.edges(data=True) if d['weight'] <=weight_threshold]
            pos=nx.graphviz_layout(cox) # positions for all nodes
            nx.draw_networkx_nodes(cox,pos,
                node_color= [s*4500 for s in nx.eigenvector_centrality(cox).values()],
                node_size = [s*6+20  for s in nx.degree(cox).values()],
                alpha=0.7)
            # edges
            nx.draw_networkx_edges(cox,pos,edgelist=elarge,
                                width=1, alpha=0.5, edge_color='black') #, edge_cmap=plt.cm.Blues
            nx.draw_networkx_edges(cox,pos,edgelist=esmall,
                                width=0.3,alpha=0.5,edge_color='yellow',style='dotted')
            # labels
            nx.draw_networkx_labels(cox,pos,font_size=10,font_family='sans-serif')
            plt.axis('off')
        else:
            nx.draw_graphviz(cox, with_labels=True,
                         alpha = 0.8, width=0.1,
                         fontsize=9,
                         node_color = [s*4 for s in nx.eigenvector_centrality(cox).values()],
                         node_size = [s*6+20 for s in nx.degree(cox).values()])
开发者ID:datapractice,项目名称:machinelearning,代码行数:35,代码来源:net_lit_anal.py


示例13: draw_graph

def draw_graph(G):
	# an example using Graph as a weighted network.
	# __author__ = """Aric Hagberg ([email protected])"""
	try:
	    import matplotlib.pyplot as plt
	except:
	    raise

	elarge = [(u,v) for (u,v,d) in G.edges(data = True) if d['weight'] > 0.5]
	esmall = [(u,v) for (u,v,d) in G.edges(data = True) if d['weight'] <= 0.5]

	pos = nx.spring_layout(G) # positions for all nodes

	# nodes
	nx.draw_networkx_nodes(G, pos, node_size = 200)

	# edges
	nx.draw_networkx_edges(G, pos, edgelist = elarge, width = 0.4)
	nx.draw_networkx_edges(G, pos, edgelist = esmall, width = 0.4, alpha = 0.6, style = 'dashed')

	# labels
	nx.draw_networkx_labels(G, pos, font_size = 6, font_family = 'sans-serif')

	print 'number of cliques/clusters:', nx.graph_number_of_cliques(G)
	print 'time:', time.time() - start
	plt.show()
开发者ID:danielgribel,项目名称:clustering,代码行数:26,代码来源:grasp.py


示例14: draw_molecule

def draw_molecule(molecule):
    # Create a new NetworkX graph
    g = nx.Graph()
    # For each vertex and edge in molecule graph add node and edge in NetworkX graph
    for n in molecule.vertices():
        g.add_node(molecule.position_of_vertex(n), element=n.label)
    for e in molecule.edges():
        if e.single:
            g.add_edge(molecule.endpoints_position(e)[0], molecule.endpoints_position(e)[1], type='single')
        elif e.double:
            g.add_edge(molecule.endpoints_position(e)[0], molecule.endpoints_position(e)[1], type='double')
        elif e.triple:
            g.add_edge(molecule.endpoints_position(e)[0], molecule.endpoints_position(e)[1], type='triple')
        elif e.quadruple:
            g.add_edge(molecule.endpoints_position(e)[0], molecule.endpoints_position(e)[1], type='quadruple')
        elif e.aromatic:
            g.add_edge(molecule.endpoints_position(e)[0], molecule.endpoints_position(e)[1], type='aromatic')

    # Set the layout
    pos = nx.spring_layout(g, iterations=30)
    # Display the element type and edge type as labels
    labels = dict((n,d['element']) for n,d in g.nodes(data=True))
    edge_labels = dict(((u,v),d['type']) for u,v,d in g.edges(data=True))
    # Add the labels to the graph
    nx.draw(g, pos=pos, node_color='w')
    nx.draw_networkx_labels(g, pos=pos, labels=labels)
    nx.draw_networkx_edge_labels(g, pos=pos, edge_labels=edge_labels)
    # Display the completed graph
    plt.show()
    return g
开发者ID:MSMcDowall,项目名称:CharacteristicSubstructure,代码行数:30,代码来源:draw_molecule.py


示例15: plot

    def plot(self, show_labels=False):
        nodes = nx.draw_networkx_nodes(self,
                                       self.pos,
                                       node_size=NODE_SIZE_NORMAL,
                                       node_color=NODE_COLOR_NORMAL,
                                       linewidths=NODE_LINEWIDTH_NORMAL,
                                       alpha=NODE_ALPHA_NORMAL)
        if nodes != None:
            nodes.set_edgecolor(NODE_BORDER_COLOR_NORMAL)
        ws = nx.get_node_attributes(self, 'w')
        sizes = [NODE_SIZE_PHOTO_MIN + ws[v]*NODE_SIZE_PHOTO_SCALE
                 for v in self.photo_nodes()]
        nodes = nx.draw_networkx_nodes(self,
                                       self.pos,
                                       nodelist=self.photo_nodes(),
                                       node_shape=NODE_SHAPE_PHOTO,
                                       node_size=sizes,
                                       node_color=NODE_COLOR_PHOTO)

        if nodes != None:
            nodes.set_edgecolor(NODE_BORDER_COLOR_PHOTO)
        if show_labels:
            nx.draw_networkx_labels(self,
                                    self.pos,
                                    font_color=LABEL_COLOR_NORMAL,
                                    font_size=LABEL_FONT_SIZE_NORMAL)
        nx.draw_networkx_edges(self,
                               self.pos,
                               width=EDGE_WIDTH_NORMAL,
                               edge_color=EDGE_COLOR_NORMAL,
                               alpha=EDGE_ALPHA_NORMAL)
开发者ID:3lectrologos,项目名称:pyor,代码行数:31,代码来源:util.py


示例16: plot_networkx_topology_graph

def plot_networkx_topology_graph(topology):
    import matplotlib.pyplot as plt
    import networkx as nx

    G = nx.Graph()
    top_graph = topology.get_graph()
    labels = {}
    types = {}
    n_types = 0
    colors = []
    for v in top_graph.get_vertices():
        G.add_node(v.particle_index)
        labels[v.particle_index] = v.label
        if not v.particle_type() in types:
            types[v.particle_type()] = n_types
            n_types += 1
        colors.append(types[v.particle_type()])
    for v in top_graph.get_vertices():
        for vv in v:
            G.add_edge(v.particle_index, vv.get().particle_index)

    pos = nx.spring_layout(G)  # positions for all nodes

    nx.draw_networkx_nodes(G, pos, node_size=700, node_color=colors, cmap=plt.cm.summer)
    nx.draw_networkx_edges(G, pos, width=3)
    nx.draw_networkx_labels(G, pos, font_size=20, labels=labels, font_family='sans-serif')
    plt.show()
开发者ID:readdy,项目名称:readdy,代码行数:27,代码来源:topology_utils.py


示例17: draw_graph

def draw_graph(username, password, filename='graph.txt', label_flag=True, remove_isolated=True, different_size=True, iso_level=10, node_size=40):
    """Reading data from file and draw the graph.If not exists, create the file and re-scratch data from net"""
    print "Generating graph..."
    try:
        with open(filename, 'r') as f:
            G = p.load(f)
    except:
        G = getgraph(username, password)
        with open(filename, 'w') as f:
            p.dump(G, f)
    #nx.draw(G)
    # Judge whether remove the isolated point from graph
    if remove_isolated is True:
        H = nx.empty_graph()
        for SG in nx.connected_component_subgraphs(G):
            if SG.number_of_nodes() > iso_level:
                H = nx.union(SG, H)
        G = H
    # Ajust graph for better presentation
    if different_size is True:
        L = nx.degree(G)
        G.dot_size = {}
        for k, v in L.items():
            G.dot_size[k] = v
        node_size = [G.dot_size[v] * 10 for v in G]
    pos = nx.spring_layout(G, iterations=50)
    nx.draw_networkx_edges(G, pos, alpha=0.2)
    nx.draw_networkx_nodes(G, pos, node_size=node_size, node_color='r', alpha=0.3)
    # Judge whether shows label
    if label_flag is True:
        nx.draw_networkx_labels(G, pos, alpha=0.5)
    #nx.draw_graphviz(G)
    plt.show()

    return G
开发者ID:DAWN0226,项目名称:scripts,代码行数:35,代码来源:renren.py


示例18: plot_graph_3D

def plot_graph_3D(graph, I_shape, plot_terminal=True, plot_weights=True, font_size=7):
    w_h = I_shape[1] * I_shape[2]
    X, Y = np.mgrid[:I_shape[1], :I_shape[2]]
    aux = np.array([Y.ravel(), X[::-1].ravel()]).T
    positions = {i: aux[i] for i in xrange(w_h)}

    for i in xrange(1, I_shape[0]):
        for j in xrange(w_h):
            positions[w_h * i + j] = [positions[j][0] + 0.3 * i, positions[j][1] + 0.2 * i]

    positions['s'] = np.array([-1, int(I_shape[1] / 2)])
    positions['t'] = np.array([I_shape[2] + 0.2 * I_shape[0], int(I_shape[1] / 2)])

    nxg = graph.get_nx_graph()
    if not plot_terminal:
        nxg.remove_nodes_from(['s', 't'])

    nx.draw(nxg, pos=positions)
    nx.draw_networkx_labels(nxg, pos=positions)
    if plot_weights:
        edge_labels = dict([((u, v,), d['weight'])
                     for u, v, d in nxg.edges(data=True)])
        nx.draw_networkx_edge_labels(nxg, pos=positions, edge_labels=edge_labels, label_pos=0.3, font_size=font_size)
    plt.axis('equal')
    plt.show()
开发者ID:PNProductions,项目名称:PyMaxflow,代码行数:25,代码来源:examples_utils.py


示例19: draw_graph

    def draw_graph(self):
        import matplotlib.pyplot as plt

        elarge = [(u, v) for (u, v, d) in self._graph.edges(data=True)
                  if d['type'] == 'audio_source']
        esmall = [(u, v) for (u, v, d) in self._graph.edges(data=True)
                  if d['type'] == 'data_source']

        pos = nx.shell_layout(self._graph)  # positions for all nodes

        # nodes
        nx.draw_networkx_nodes(self._graph, pos, node_size=700)

        # edges
        nx.draw_networkx_edges(self._graph, pos, edgelist=elarge,
                               arrows=True)
        nx.draw_networkx_edges(self._graph, pos, edgelist=esmall,
                               alpha=0.5, edge_color='b',
                               style='dashed', arrows=True)

        # labels
        labels = {node: repr(self._graph.node[node]['processor']) for node in self._graph.nodes()}
        nx.draw_networkx_labels(self._graph, pos, labels, font_size=20,
                                font_family='sans-serif')

        plt.axis('off')
        plt.show()  # display
开发者ID:MikeLevine,项目名称:speaky,代码行数:27,代码来源:core.py


示例20: _graph_intelligence_nx

 def _graph_intelligence_nx(bot, file_path):
     # TODO: Make BehaviorGraph track the launch node and mark it in the graph output
     print("Saving Champion Intelligence Graph...")
     behavior_nodes = bot.behavior.behavior_nodes
     network = nx.DiGraph()
     network.add_nodes_from(behavior_nodes)
     # Add the behavior nodes to the network and link them together
     for node in behavior_nodes:
         if node.node_type == NodeRegister.statement:
             network.add_edge(node, node.next_node, label='')
         elif node.node_type == NodeRegister.conditional:
             network.add_edge(node, node.true_node, label='1')
             network.add_edge(node, node.false_node, label='0')
     # Draw the network
     layout = nx.shell_layout(network, scale=3)
     plt.figure(figsize=(10, 10))
     plt.axis('equal')
     plt.title("%s: Born:%s, Age:%s, Peak Energy:%s, Children:%s" %
               (str(bot), str(bot.birthday), str(bot.age), str(bot.peak_energy), str(bot.number_children)))
     nx.draw_networkx_edges(network, layout, width=0.5, alpha=0.75, edge_color='black', arrows=True)
     statement_color = '#D7E7F7'
     conditional_color = '#F7D7DA'
     colors = [statement_color if node.node_type == NodeRegister.statement else conditional_color
               for node in network.nodes()]
     nx.draw_networkx_nodes(network, layout, node_size=1800, node_color=colors, alpha=1)
     # Reformat node names to make them easier to read
     names = [(node, str(node.function.__name__).replace('_', '\n')) for node in behavior_nodes]
     labels = {key: value for (key, value) in names}
     nx.draw_networkx_labels(network, layout, labels, font_size=10, font_family='sans-serif')
     edge_names = nx.get_edge_attributes(network, 'label')
     nx.draw_networkx_edge_labels(network, layout, edge_labels=edge_names, label_pos=0.7)
     plt.axis('off')
     plt.savefig(file_path + '.png', dpi=80, pad_inches=0.0, bbox_inches='tight')
开发者ID:sjirjies,项目名称:nss,代码行数:33,代码来源:world.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python networkx.draw_networkx_nodes函数代码示例发布时间:2022-05-27
下一篇:
Python networkx.draw_networkx_edges函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap