python类spring_layout()的实例源码

egocentric_network_1_5.py 文件源码 项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def DrawGraph(G, egocentric_network_edge_list, egocentric_network_node_list, vert):
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8)  #with_labels=true is to show the node number in the output graph
    nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
    nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
    nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
    return pos
egocentric_network_2.py 文件源码 项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def DrawGraph(G, egocentric_network_edge_list, egocentric_network_node_list, vert):
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8)  #with_labels=true is to show the node number in the output graph
    nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
    nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
    nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
    return pos
egocentric_network_1.py 文件源码 项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def DrawGraph(G,egocentric_network_edge_list,egocentric_network_node_list, vert):
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels = True, node_color = 'blue', alpha = 0.8)  #with_labels=true is to show the node number in the output graph
    nx.draw_networkx_edges(G, pos, edgelist = egocentric_network_edge_list , width = 2.5, alpha = 0.8, edge_color = 'red')
    nx.draw_networkx_nodes(G,pos, nodelist = egocentric_network_node_list, node_color = 'red', alpha = 0.5)
    nx.draw_networkx_nodes(G,pos,nodelist=[vert],node_color='green',node_size=500,alpha=0.8)
    return pos
dijsktras.py 文件源码 项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def DrawGraph(G):
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels = True)  #with_labels=true is to show the node number in the output graph
    edge_labels = dict([((u, v), d['length']) for u, v, d in G.edges(data = True)])
    nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, label_pos = 0.3, font_size = 11) #prints weight on all the edges
    return pos



#main function
kruskals_quick_union.py 文件源码 项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def DrawGraph(G):
    pos = nx.spring_layout(G)
    nx.draw(G, pos, with_labels = True)  # with_labels=true is to show the node number in the output graph
    edge_labels = nx.get_edge_attributes(G, 'length')
    nx.draw_networkx_edge_labels(G, pos, edge_labels = edge_labels, font_size = 11) #    prints weight on all the edges
    return pos



# main function
test_workflow_dependencies.py 文件源码 项目:juicer 作者: eubr-bigsea 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def debug_instance(instance_wf):
    print '*' * 20
    print instance_wf.graph.nodes(data=False)
    print '*' * 21
    print instance_wf.graph.edges()
    print '*' * 22
    print instance_wf.graph.is_multigraph()
    print '*' * 23
    print instance_wf.graph.number_of_edges()
    print '*' * 24
    print instance_wf.sorted_tasks
    print '*' * 25
    test = instance_wf.graph.reverse()
    print test.edges()
    print '*' * 26
    print instance_wf.graph.in_degree()
    print instance_wf.check_in_degree_edges()
    print '*' * 27
    print instance_wf.graph.out_degree()
    print instance_wf.check_out_degree_edges()
    print '*' * 28
    x = instance_wf.get_operations()[0]
    print x['ports']

    # print instance_wf.get_ports_from_operation_tasks('')
    # Show image
    # pos = nx.spring_layout(instance_wf.graph)
    # pos = nx.fruchterman_reingold_layout(instance_wf.graph)
    # nx.draw(instance_wf.graph, pos, node_color='#004a7b', node_size=2000,
    #         edge_color='#555555', width=1.5, edge_cmap=None,
    #         with_labels=True, style='dashed',
    #         label_pos=50.3, alpha=1, arrows=True, node_shape='s',
    #         font_size=8,
    #         font_color='#FFFFFF')
    # plt.show()
    # plt.savefig(filename, dpi=300, orientation='landscape', format=None,
                 # bbox_inches=None, pad_inches=0.1)
dependencygraph.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def malt_demo(nx=False):
    """
    A demonstration of the result of reading a dependency
    version of the first sentence of the Penn Treebank.
    """
    dg = DependencyGraph("""Pierre  NNP     2       NMOD
Vinken  NNP     8       SUB
,       ,       2       P
61      CD      5       NMOD
years   NNS     6       AMOD
old     JJ      2       NMOD
,       ,       2       P
will    MD      0       ROOT
join    VB      8       VC
the     DT      11      NMOD
board   NN      9       OBJ
as      IN      9       VMOD
a       DT      15      NMOD
nonexecutive    JJ      15      NMOD
director        NN      12      PMOD
Nov.    NNP     9       VMOD
29      CD      16      NMOD
.       .       9       VMOD
""")
    tree = dg.tree()
    tree.pprint()
    if nx:
        # currently doesn't work
        import networkx
        from matplotlib import pylab

        g = dg.nx_graph()
        g.info()
        pos = networkx.spring_layout(g, dim=1)
        networkx.draw_networkx_nodes(g, pos, node_size=50)
        # networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
        networkx.draw_networkx_labels(g, pos, dg.nx_labels)
        pylab.xticks([])
        pylab.yticks([])
        pylab.savefig('tree.png')
        pylab.show()
communityDetectionEngine.py 文件源码 项目:BrainModulyzer 作者: sugeerth 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def initUI(self):
        scene = QtGui.QGraphicsScene(self)
        scene.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
        self.setScene(scene)
        self.NodeIds = []
        self.centrality = []
        self.Scene_to_be_updated = scene
        self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
        self.setRenderHint(QtGui.QPainter.Antialiasing)
        self.setInteractive(True)
        self.setTransformationAnchor(QtGui.QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QtGui.QGraphicsView.AnchorViewCenter)
        self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)

        i = 0

        self.communityPos = nx.nx_pydot.graphviz_layout(self.induced_graph,prog='fdp',args='-Gsep=.25,-GK=20-Eweight=2')
        # self.communityPos = nx.spring_layout(self.induced_graph,pos=self.Pos,weight='weight',scale=450)
        for node in self.induced_graph.nodes():
            i = i + 1
            node_value=Node(self.Graph,i,self.correlationTableObject,True)
            self.NodeIds.append(node_value)
            scene.addItem(node_value)
            x,y=self.communityPos[node]
            node_value.setPos(x,y)
            node_value.PutColor(self.clut[i-1])
        k =0
        for i,j in self.induced_graph.edges():
                Weight = self.induced_graph[i][j]['weight'] 
                Edge_Value = 1+(float(Weight-self.Min1)/(self.Max1 - self.Min1))*5
                scene.addItem(Edge(self.Graph,self.NodeIds[i],self.NodeIds[j],k, i,j,self.Max,((self.Matrix[j,i]-self.Min1)/(self.Max1 - self.Min1))*5,True))
                k = k + 1 

        self.setSceneRect(self.Scene_to_be_updated.itemsBoundingRect())
        self.setScene(self.Scene_to_be_updated)
        self.fitInView(self.Scene_to_be_updated.itemsBoundingRect(),QtCore.Qt.KeepAspectRatio)
        self.scaleView(math.pow(2.5, -900 / 1040.0))

        self.nodes = [item for item in scene.items() if isinstance(item, Node)]
        self.edges = [item for item in scene.items() if isinstance(item, Edge)]
syngraph.py 文件源码 项目:atap 作者: foxbook 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def draw_text_graph(G):
    plt.figure(figsize=(18,12))
    pos = nx.spring_layout(G, scale=18)
    nx.draw_networkx_nodes(G, pos, node_color="white", linewidths=0, node_size=500)
    nx.draw_networkx_labels(G, pos, font_size=10)
    nx.draw_networkx_edges(G, pos)
    plt.xticks([])
    plt.yticks([])
Measurements.py 文件源码 项目:marve 作者: khundman 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _build_graph(show=False):
    """Load word dependencies into graph using networkx. Enables easy traversal of dependencies for parsing particular patterns.
    One graph is created for each sentence.

    Args:
        show (bool): If set to True, labeled visualization of network will be opened via matplotlib for each sentence

    Returns:
        None: Global variable G is set from within function

    """
    global G
    G = nx.Graph()
    node_labels, edge_labels = {}, {}
    for idx, dep in enumerate(A.deps):

        types = ["dependent", "governor"]

        # nodes, labels
        for x in types:
            G.add_node(str(dep[x]), word=dep[x + "Gloss"], pos=A.lookup[dep[x]]["pos"])
            node_labels[str(dep[x])] = dep[x + "Gloss"] + " : " + A.lookup[dep[x]]["pos"]

        # edges, labels
        G.add_edge(str(dep[types[0]]), str(dep[types[1]]), dep=dep["dep"])
        edge_labels[(str(dep[types[0]]), str(dep[types[1]]))] = dep["dep"]

    if show == True:
        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos=pos, labels=node_labels, node_color="white", alpha=.5)
        nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=edge_labels)
        plt.show()


#########################################
# Dependency / POS parsing functions
#########################################
Data_Prepare.py 文件源码 项目:PhD 作者: wutaoadeny 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def Drawcomgraph(G):
    #Draw the graph
    pos=nx.spring_layout(G)
    nx.draw_networkx_edges(G, pos, alpha=0.4)
    nx.draw_networkx_labels(G, pos, font_size=10, font_family='sans-serif')
    #colorList = ['SeaGreen','yellow','brown','pink','purple','blue','green','Salmon','red','c','magenta','orange','white','black','y','skyblue','GreenYellow','cyan']#,'aqua'
    nx.draw_networkx_nodes(G, pos, nodelist=G.nodes(), node_size=150)
    plt.title("Network Community Analysis")
    plt.show()
net_distribution.py 文件源码 项目:tweetopo 作者: zthxxx 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def __init__(self, edges, **kwargs):
        super().__init__(edges, **kwargs)
        self.pos = nx.spring_layout(self.G, iterations=100)
        self.get_measures()
AnalysisElegans.py 文件源码 项目:Networks 作者: dencesun 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def draw_network(DG):
    nx.draw_networkx(DG, pos=nx.spring_layout(DG), node_color = 'red')
    plt.axis('off') # turn off axis
    plt.savefig('c-elegans.svg')
    # plt.show()
AnalysisElegans.py 文件源码 项目:Networks 作者: dencesun 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def centrality(DG):
    in_degree_centrality = nx.in_degree_centrality(DG)
    out_degree_centrality = nx.out_degree_centrality(DG)
    with open('/home/sun/PycharmProjects/Network/in_degree_centrality.csv', 'w') as f:
        for k, v in in_degree_centrality.items():
            f.write(str(k) + ': ' + str(v) + '\n')
        f.close()

    with open('/home/sun/PycharmProjects/Network/out_degree_centrality.csv', 'w') as f:
        for k, v in out_degree_centrality.items():
            f.write(str(k) + ': ' + str(v) + '\n')
        f.close()


# def main():
#     data = '/home/sun/PycharmProjects/Network/C-elegans-frontal.txt'
#     # data = 'www.adj'
#     DG = create_network(data)
#
#     # draw_network(DG)
#     # clustering_coefficient(DG)
#     # centrality(DG)
#     degree_distribution(DG)
#
# if __name__ == '__main__':
#     main()
#
#     # DG = nx.DiGraph()
#     # DG.add_edge(1,2)
#     # print(DG.edges())
#     # # pos = nx.nx_agraph.graphviz_layout(DG)
#     # nx.draw_networkx(DG, pos = nx.spring_layout(DG))
#     # plt.show()
#     # plt.ishold()
#     # plt.draw(DG)
generate_net.py 文件源码 项目:conceptNet_55_client 作者: zhouhoo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def plot_and_save_net(self, picpath='../output/net.png'):

        net = nx.DiGraph()

        edge_label = dict()
        for edge in self.edges:
            net.add_edge(edge[0], edge[1], weight=1)
            edge_label[(edge[0], edge[1])] = edge[3]
            if len(edge_label) > 8:
                break
                # edge_label.update({(edge[0], edge[1]) : edge[2]})

        pos = nx.spring_layout(net, k=20)  # positions for all nodes

        # nodes
        nx.draw_networkx_nodes(net, pos, node_size=6000, node_color="green")

        # edges
        nx.draw_networkx_edges(net, pos,
                               width=1.5, alpha=0.5, arrows=True, edge_color='black')
        # labels
        nx.draw_networkx_labels(net, pos, font_size=20)

        nx.draw_networkx_edge_labels(net, pos, edge_labels=edge_label, label_pos=0.5, font_family='sans-serif')

        plt.axis('off')
        plt.savefig(picpath)  # save as png
        plt.show()  # display
hcPlotting.py 文件源码 项目:synchrony 作者: cknd 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def get_reusable_springlayout(network,seed=0):
    """returns a networkx spring layout function with deterministic behaviour
    (useful to draw a series of thumbnails)"""
    rng = RandomState(seed)
    nodelist = network.nodes()
    initpos = dict(zip(nodelist,rng.rand(len(nodelist),2)))
    return lambda net:nx.spring_layout(net,pos=initpos)
dependencygraph.py 文件源码 项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda 作者: SignalMedia 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def malt_demo(nx=False):
    """
    A demonstration of the result of reading a dependency
    version of the first sentence of the Penn Treebank.
    """
    dg = DependencyGraph("""Pierre  NNP     2       NMOD
Vinken  NNP     8       SUB
,       ,       2       P
61      CD      5       NMOD
years   NNS     6       AMOD
old     JJ      2       NMOD
,       ,       2       P
will    MD      0       ROOT
join    VB      8       VC
the     DT      11      NMOD
board   NN      9       OBJ
as      IN      9       VMOD
a       DT      15      NMOD
nonexecutive    JJ      15      NMOD
director        NN      12      PMOD
Nov.    NNP     9       VMOD
29      CD      16      NMOD
.       .       9       VMOD
""")
    tree = dg.tree()
    tree.pprint()
    if nx:
        # currently doesn't work
        import networkx
        from matplotlib import pylab

        g = dg.nx_graph()
        g.info()
        pos = networkx.spring_layout(g, dim=1)
        networkx.draw_networkx_nodes(g, pos, node_size=50)
        # networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
        networkx.draw_networkx_labels(g, pos, dg.nx_labels)
        pylab.xticks([])
        pylab.yticks([])
        pylab.savefig('tree.png')
        pylab.show()
link_network.py 文件源码 项目:taikutsu_blog_works 作者: hokekiyoo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def visualize(G, savename, savegml):
    pos = nx.spring_layout(G) # ???????????????????????????
    nx.draw(G, pos, with_labels=True,alpha=0.3,font_size=0.0,node_size=10) # ?????? ????????????????????
    plt.savefig(savename+".png")
    plt.show()
    if savegml:
        nx.write_gml(G,savename+".gml")
dependencygraph.py 文件源码 项目:neighborhood_mood_aws 作者: jarrellmark 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def malt_demo(nx=False):
    """
    A demonstration of the result of reading a dependency
    version of the first sentence of the Penn Treebank.
    """
    dg = DependencyGraph("""Pierre  NNP     2       NMOD
Vinken  NNP     8       SUB
,       ,       2       P
61      CD      5       NMOD
years   NNS     6       AMOD
old     JJ      2       NMOD
,       ,       2       P
will    MD      0       ROOT
join    VB      8       VC
the     DT      11      NMOD
board   NN      9       OBJ
as      IN      9       VMOD
a       DT      15      NMOD
nonexecutive    JJ      15      NMOD
director        NN      12      PMOD
Nov.    NNP     9       VMOD
29      CD      16      NMOD
.       .       9       VMOD
""")
    tree = dg.tree()
    tree.pprint()
    if nx:
        # currently doesn't work
        import networkx
        from matplotlib import pylab

        g = dg.nx_graph()
        g.info()
        pos = networkx.spring_layout(g, dim=1)
        networkx.draw_networkx_nodes(g, pos, node_size=50)
        # networkx.draw_networkx_edges(g, pos, edge_color='k', width=8)
        networkx.draw_networkx_labels(g, pos, dg.nx_labels)
        pylab.xticks([])
        pylab.yticks([])
        pylab.savefig('tree.png')
        pylab.show()
plot_utils.py 文件源码 项目:nodeembedding-to-communityembedding 作者: andompesta 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def graph_plot(G,
               graph_name,
               nodes_color_fn=_pos_coloring,
               node_position_path="./data",
               node_position_file=True,
               show=True):

    if node_position_file:
        spring_pos = pickle.load(open(path_join(node_position_path, graph_name, 'node_pos.bin'), "rb"))
    else:
        spring_pos = nx.spring_layout(G)
        pickle.dump(spring_pos, open(path_join(node_position_path, graph_name, 'node_pos.bin'), "wb"))

    spring_pos_values = np.array(list(spring_pos.values()))
    norm_pos = np.linalg.norm(spring_pos_values, axis=1)
    nodes_color = nodes_color_fn(G, norm_pos)

    plt.figure(figsize=(5, 5))
    plt.axis("off")
    nx.draw_networkx(G, node_color=nodes_color, pos=spring_pos, camp=plt.get_cmap(CAMP), nodelist=sorted(G.nodes()))

    if show:
        plt.show()
    else:
        plt.clf()
        plt.close()

    return nodes_color


问题


面经


文章

微信
公众号

扫码关注公众号