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


Python networkx.random_layout函数代码示例

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


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

示例1: test_scale_and_center_arg

    def test_scale_and_center_arg(self):
        G = nx.complete_graph(9)
        G.add_node(9)
        vpos = nx.random_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        vpos = nx.spring_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        vpos = nx.spectral_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2, center=(4,5))
        # circular can have twice as big length
        vpos = nx.circular_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2*2, center=(4,5))
        vpos = nx.shell_layout(G, scale=2, center=(4,5))
        self.check_scale_and_center(vpos, scale=2*2, center=(4,5))

        # check default center and scale
        vpos = nx.random_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.spring_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.spectral_layout(G)
        self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5))
        vpos = nx.circular_layout(G)
        self.check_scale_and_center(vpos, scale=2, center=(0,0))
        vpos = nx.shell_layout(G)
        self.check_scale_and_center(vpos, scale=2, center=(0,0))
开发者ID:JFriel,项目名称:honours_project,代码行数:26,代码来源:test_layout.py

示例2: generateNetworkCoordinates

def generateNetworkCoordinates(G, forRadius=4, forSize=(800,600)):#, layout='dot'):
    '''
    """
    generates network coordinates in the attribute 'pos'
    :param G:
    :Param layout: neato|dot|twopi|circo|fdp|nop
    :return:
    """
    ag = networkx.nx_agraph.to_agraph(G)
    ag.layout(prog=layout)
    ag.write(path='dot.dot')
    G = networkx.nx_agraph.from_agraph(ag)
    '''
    import networkx as nx
    if forSize[0] > forSize[1]:
        scale = 1.0-(float(forRadius)/float(forSize[1]))
    else:
        scale = 1.0-(float(forRadius)/float(forSize[0]))

    try:
        G = nx.random_layout(G, dim=2, scale=scale, center=(0,0))
    except TypeError: # Fixes the problem of having another version of nx
        G = nx.random_layout(G, dim=2)
        for (key,(x,y)) in G.items():
            x = 2 * x - 1
            y = 2 * y - 1
            G[key] = [x,y]

    return G
开发者ID:etteerr,项目名称:NeuronNet,代码行数:29,代码来源:python27Ca2VideoMaker.py

示例3: simplePlot

def simplePlot(graph, layout = "shell", nodeSize= 600, widthEdge=2):
    """ Plot a directed graph using igraph library.
        
        @type graph: graph
        @param graph: a graph to plot
        @type layout: string
        @param layout: node position method (shell, circular, random, spring, spectral)

    """
    G=nx.DiGraph()
    for node in graph.keys():
        G.add_node(node)
  
    #add edges
    for v1 in graph.keys():
       for v2 in graph[v1]:
          G.add_edge(v1, v2)
  
    # draw graph
    if layout == 'circular':
      pos = nx.circular_layout(G)
    elif layout == 'random':
      pos = nx.random_layout(G)
    elif layout == 'spring':
      pos = nx.random_layout(G)
    elif layout == 'spectral':
      pos = nx.spectral_layout(G)
    else:
      pos = nx.shell_layout(G)
  
    nx.draw(G, pos, edge_color='#796d54', alpha=1, node_color='#4370D8',cmap=plt.cm.Blues, node_size=nodeSize, width=widthEdge)
  
    plt.show()
开发者ID:emanuelepesce,项目名称:NetworksSimulator,代码行数:33,代码来源:drawGraph.py

示例4: test_empty_graph

 def test_empty_graph(self):
     G=nx.Graph()
     vpos = nx.random_layout(G)
     vpos = nx.circular_layout(G)
     vpos = nx.spring_layout(G)
     vpos = nx.fruchterman_reingold_layout(G)
     vpos = nx.shell_layout(G)
     vpos = nx.spectral_layout(G)
     # center arg
     vpos = nx.random_layout(G, scale=2, center=(4,5))
     vpos = nx.circular_layout(G, scale=2, center=(4,5))
     vpos = nx.spring_layout(G, scale=2, center=(4,5))
     vpos = nx.shell_layout(G, scale=2, center=(4,5))
     vpos = nx.spectral_layout(G, scale=2, center=(4,5))
开发者ID:JFriel,项目名称:honours_project,代码行数:14,代码来源:test_layout.py

示例5: test_single_node

 def test_single_node(self):
     G = nx.Graph()
     G.add_node(0)
     vpos = nx.random_layout(G)
     vpos = nx.circular_layout(G)
     vpos = nx.spring_layout(G)
     vpos = nx.fruchterman_reingold_layout(G)
     vpos = nx.shell_layout(G)
     vpos = nx.spectral_layout(G)
     # center arg
     vpos = nx.random_layout(G, scale=2, center=(4,5))
     vpos = nx.circular_layout(G, scale=2, center=(4,5))
     vpos = nx.spring_layout(G, scale=2, center=(4,5))
     vpos = nx.shell_layout(G, scale=2, center=(4,5))
     vpos = nx.spectral_layout(G, scale=2, center=(4,5))
开发者ID:JFriel,项目名称:honours_project,代码行数:15,代码来源:test_layout.py

示例6: draw_graph

    def draw_graph(self):
        """
            Draws the graph of relations
        """
        G=nx.Graph()
        
        list_location1 = []
        list_location2 = []
        list_location3 = []
        list_location4 = []
        
        for citizen in self.citizens:
            G.add_node(citizen.id)
            if citizen.location == 1:
                list_location1.append(citizen.id)
            elif citizen.location == 2:
                list_location2.append(citizen.id)
            elif citizen.location == 3:
                list_location3.append(citizen.id)
            else: 
                list_location4.append(citizen.id)

        for citizen in self.citizens:
            for friend in citizen.friends:
                G.add_edge(citizen.id,friend.id)

        pos = nx.random_layout(G)
        nx.draw_networkx_nodes(G,pos,node_size=60,nodelist=list_location1, node_color='r')
        nx.draw_networkx_nodes(G,pos,node_size=60,nodelist=list_location2, node_color='g')
        nx.draw_networkx_nodes(G,pos,node_size=60,nodelist=list_location3, node_color='b')
        nx.draw_networkx_nodes(G,pos,node_size=60,nodelist=list_location4, node_color='y')
        nx.draw_networkx_edges(G,pos, width=1)

        plt.show()
开发者ID:guilhermeamorim,项目名称:neodemocracy,代码行数:34,代码来源:simulator.py

示例7: display_community_graph

 def display_community_graph(self):
     """
     Display the subgraph identified by community detection
     """
     plt.figure(num=None, figsize=(70, 50), dpi=80)
     up_pos_cnm=nx.random_layout(user_post_graph_cnm)
     for (idx, comm) in enumerate(self.sig_communities_by_id):
         comm_u_cnm = []
         comm_p_cnm = []
         for n in self.all_post_users:
             if n in comm:
                 comm_u_cnm.append(n)
         for n in self.all_posts_res:
             if n in comm:
                 comm_p_cnm.append(n)
         nx.draw_networkx_nodes(self.user_post_graph_cnm,up_pos_cnm,
                                nodelist=comm_u_cnm,
                                node_color=self.group_colors[idx],
                                alpha=0.8)
         nx.draw_networkx_nodes(self.user_post_graph_cnm,up_pos_cnm,
                                nodelist=comm_p_cnm,
                                node_color=self.group_colors[idx],
                                alpha=0.8)
         elsg1_cnm = [e for e in self.up_likes if e[0] in comm_u_cnm and e[1] in comm_p_cnm]
         ecsg1_cnm = [e for e in self.up_comments if e[0] in comm_u_cnm and e[1] in comm_p_cnm]
         epsg1_cnm = [e for e in self.up_posts if e[0] in comm_u_cnm and e[1] in comm_p_cnm]
         nx.draw_networkx_edges(self.user_post_graph_cnm,up_pos,edgelist=elsg1_cnm,alpha=0.5,edge_color='m')
         nx.draw_networkx_edges(self.user_post_graph_cnm,up_pos,edgelist=ecsg1_cnm,alpha=0.5,edge_color='teal')
         nx.draw_networkx_edges(self.user_post_graph_cnm,up_pos,edgelist=epsg1_cnm,alpha=0.5,edge_color='y')
开发者ID:charlescearl,项目名称:blogs,代码行数:29,代码来源:graph_analysis.py

示例8: draw_graph

def draw_graph(graph, labels=None, graph_layout='spring',
               node_size=1600, node_color='blue', node_alpha=0.3,
               node_text_size=12,
               edge_color='blue', edge_alpha=0.3, edge_tickness=1,
               edge_text_pos=0.3,
               text_font='sans-serif'):

	# create networkx graph
	G=nx.Graph()
	# add edges
	for edge in graph:
		G.add_edge(edge[0], edge[1])

	# these are different layouts for the network you may try
	if graph_layout == 'spring':
		graph_pos=nx.spring_layout(G)
	elif graph_layout == 'spectral':
		graph_pos=nx.spectral_layout(G)
	elif graph_layout == 'random':
		graph_pos=nx.random_layout(G)
	else:
		graph_pos=nx.shell_layout(G)

	# draw graph
	nx.draw_networkx_nodes(G,graph_pos,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)

	plt.show()
开发者ID:yh1008,项目名称:socialNetwork,代码行数:29,代码来源:social_graph.py

示例9: calcMetrics

def calcMetrics():
    print('\nTrips:')
    for trip in trips:
        trip.display()
    print('\nPairs:')
    for a, b in itertools.combinations(trips, 2):
        # if isTimeTestFail(): continue
        bestDist = getBestDist(a, b)
        sumDist = a.dist + b.dist
        if bestDist > sumDist: continue
        minDist = min(a.dist, b.dist)
        maxDist = max(a.dist, b.dist)
        delta = sumDist - bestDist
        coPathCoeff = maxDist / bestDist
        effect = delta / bestDist
        weight = effect * coPathCoeff
        G.add_edge(a, b, weight=weight)
        print('edge is added', weight)

    pos = nx.random_layout(G)
    nx.draw_networkx_nodes(G, pos)
    nx.draw_networkx_edges(G, pos, width=weight,)
    plt.axis('off')
    plt.savefig("weighted_graph.png")  # save as png
    plt.show()  # display
开发者ID:LukeSkypewalker,项目名称:Python,代码行数:25,代码来源:metrica.py

示例10: draw_graph

def draw_graph(G, labels=None, graph_layout='shell',
               node_size=1600, node_color='blue', node_alpha=0.3,
               node_text_size=12,
               edge_color='blue', edge_alpha=0.3, edge_tickness=1,
               edge_text_pos=0.3,
               text_font='sans-serif'):

    # these are different layouts for the network you may try
    # shell seems to work best
    if graph_layout == 'spring':
        graph_pos=nx.spring_layout(G)
    elif graph_layout == 'spectral':
        graph_pos=nx.spectral_layout(G)
    elif graph_layout == 'random':
        graph_pos=nx.random_layout(G)
    else:
        graph_pos=nx.shell_layout(G)
    # draw graph
    nx.draw_networkx_nodes(G,graph_pos,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)
    nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=labels, 
                                 label_pos=edge_text_pos)
    # show graph
    frame = plt.gca()
    frame.axes.get_xaxis().set_visible(False)
    frame.axes.get_yaxis().set_visible(False)

    plt.show()
开发者ID:alanshutko,项目名称:hia-examples,代码行数:32,代码来源:disease_graph.py

示例11: test_layouts

def test_layouts():
    G =nx.gnm_random_graph(10,15)

    rand = [nx.random_layout(G)]
    circ = [nx.circular_layout(G)]
    #shell = [nx.shell_layout(G)] #same as circular layout...
    spectral = [nx.spectral_layout(G)]
    tripod = [tripod_layout(G)]

    layouts = [rand,circ,spectral, tripod]
    regimes = ["random","circular","spectral", "tripod"]

    for layout in layouts:
        layout.append(nx.spring_layout(G,2,layout[0]))
        layout.append(iterate_swaps(G,layout[0]))
        layout.append(nx.spring_layout(G,2,layout[2]))
        layout.append(greedy_swapper(G,layout[0]))

    # Now have list of lists... Find lengths of edgecrossings...

    num_crossings = []
    for layout in layouts:
        for sublayout in layout:
            num_crossings.append(count_crosses(G,sublayout))

    names = []
    for regime in regimes:
        names.append(regime)
        names.append(regime + "-spring")
        names.append(regime + "-swap")
        names.append(regime + "-swap-spr")
        names.append(regime + "-greedy")

    return G, layouts, names, num_crossings
开发者ID:natlund,项目名称:disentangler,代码行数:34,代码来源:disentangler.py

示例12: draw_graph

def draw_graph(graph, labels=None, graph_layout='shell',
               node_size=120, node_color='blue', node_alpha=0.3,
               node_text_size=8,
               edge_color='blue', edge_alpha=0.3, edge_tickness=1,
               edge_text_pos=0.3,
               text_font='sans-serif'):

    # create networkx graph
    G=nx.Graph()

    # add edges
    for edge in graph:
        G.add_edge(edge[0], edge[1])

    print G.nodes()

    nodeColors = []
    nodeClients = []
    for node in G.nodes():
	if is_number(node):
		nodeColors.append(0)
	else:
		nodeColors.append(1)
		nodeClients.append(node)

    edgeColors = []
    for edge in G.edges():
	if (edge[0] in nodeClients) or (edge[1] in nodeClients):
		edgeColors.append(1)
	else:
		edgeColors.append(0)

    # these are different layouts for the network you may try
    # shell seems to work best
    if graph_layout == 'spring':
        graph_pos=nx.spring_layout(G)
    elif graph_layout == 'spectral':
        graph_pos=nx.spectral_layout(G)
    elif graph_layout == 'random':
        graph_pos=nx.random_layout(G)
    else:
        graph_pos=nx.shell_layout(G)

    # draw graph
    nx.draw_networkx_nodes(G,graph_pos,node_size=node_size, 
                           alpha=node_alpha, node_color=nodeColors)
    nx.draw_networkx_edges(G,graph_pos,width=edge_tickness,
                           alpha=edge_alpha,edge_color=edgeColors)
    nx.draw_networkx_labels(G, graph_pos,font_size=node_text_size,
                            font_family=text_font, font_weight='normal', alpha=1.0)

    # if labels is None:
    #    labels = range(len(graph))

    # edge_labels = dict(zip(graph, labels))
    # nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=edge_labels, 
    #                             label_pos=edge_text_pos)

    # show graph
    plt.show()
开发者ID:ephemeral2eternity,项目名称:parseTopology,代码行数:60,代码来源:drawNetwork.py

示例13: opti

def opti(nodeList, colorList, edgeList, cList, firstDistance):
    #Only recheck for node with new color
    for i in range(10):    
        v = random.randint(0, len(nodeList))
        
        currentDistance = 0
                
        cListBis = cList
        cListBis.pop(i)
        newColor = random.choice(cListBis)
        colorList[i] = newColor
        
        newDistance = 0
        for (u,v) in graph.edges():
            if graph.node[u]['color'] == graph.node[v]['color']:
                newDistance += 1
        
        if newDistance <= distance :
            pos=nx.random_layout(graph)
            plt.figure(3,figsize=(12,9))          
            for nodes in graph.nodes():
                nx.draw_networkx_nodes(graph, pos, nodelist=[nodes], node_color=graph.node[nodes]['color'])
            nx.draw_networkx_edges(graph, pos)      
            plt.axis('off')
            plt.draw()    
开发者ID:fonfonx,项目名称:GraphColoring,代码行数:25,代码来源:Project.py

示例14: draw_graph

def draw_graph(G, labels=None, graph_layout='shell',
               node_size=1600, node_color='blue', node_alpha=0.3,
               node_text_size=12,
               edge_color='blue', edge_alpha=0.3, edge_tickness=1,
               edge_text_pos=0.3,
               text_font='sans-serif'):

    # these are different layouts for the network you may try
    # shell seems to work best
    if graph_layout == 'spring':
        graph_pos=nx.spring_layout(G)
    elif graph_layout == 'spectral':
        graph_pos=nx.spectral_layout(G)
    elif graph_layout == 'random':
        graph_pos=nx.random_layout(G)
    else:
        graph_pos=nx.shell_layout(G)

    # draw graph
    nx.draw_networkx_nodes(G,graph_pos,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)

    if labels is None:
        labels = range(len(G))

    edge_labels = dict(zip(G, labels))
    nx.draw_networkx_edge_labels(G, graph_pos, edge_labels=labels, 
                                 label_pos=edge_text_pos)

    # show graph
    plt.show()
开发者ID:RenanGreca,项目名称:wireless-networks,代码行数:35,代码来源:dijkstra.py

示例15: draw_graph

def draw_graph(graph):

    # extract nodes from graph
    nodes = set([n1 for n1, n2 in graph] + [n2 for n1, n2 in graph])

    # create networkx graph
    G=nx.Graph()
    #G=nx.cubical_graph()

    # add nodes
    for node in nodes:
        G.add_node(node)

    # add edges
    for edge in graph:
        G.add_edge(edge[0], edge[1])

    # draw graph
    #pos = nx.shell_layout(G)
    #pos = nx.spectral_layout(G)
    pos = nx.random_layout(G) # Funciona melhor
    #pos = nx.circular_layout(G) # Mais ou menos
    #pos = nx.fruchterman_reingold_layout(G) # Funciona melhor

    #nx.draw(G, pos)
    nx.draw_networkx(G)

    # show graph
    plt.axis('off')
    plt.show()
开发者ID:AnaSLCaldeira,项目名称:EADW,代码行数:30,代码来源:graph_functions.py


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