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


Python networkx.draw_networkx_edges方法代码示例

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


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

示例1: plot_alerts

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def plot_alerts(_g, _bank_accts, _output_png):
    bank_ids = _bank_accts.keys()
    cmap = plt.get_cmap("tab10")
    pos = nx.nx_agraph.graphviz_layout(_g)

    plt.figure(figsize=(12.0, 8.0))
    plt.axis('off')

    for i, bank_id in enumerate(bank_ids):
        color = cmap(i)
        members = _bank_accts[bank_id]
        nx.draw_networkx_nodes(_g, pos, members, node_size=300, node_color=color, label=bank_id)
        nx.draw_networkx_labels(_g, pos, {n: n for n in members}, font_size=10)

    edge_labels = nx.get_edge_attributes(_g, "label")
    nx.draw_networkx_edges(_g, pos)
    nx.draw_networkx_edge_labels(_g, pos, edge_labels, font_size=6)

    plt.legend(numpoints=1)
    plt.subplots_adjust(left=0, right=1, bottom=0, top=1)
    plt.savefig(_output_png, dpi=120) 
开发者ID:IBM,项目名称:AMLSim,代码行数:23,代码来源:plot_alert_pattern_subgraphs.py

示例2: graph_att_head

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def graph_att_head(M, N, weight, ax, title):
    "credit: Jinjing Zhou"
    in_nodes=len(M)
    out_nodes=len(N)

    g = nx.bipartite.generators.complete_bipartite_graph(in_nodes,out_nodes)
    X, Y = bipartite.sets(g)
    height_in = 10
    height_out = height_in 
    height_in_y = np.linspace(0, height_in, in_nodes)
    height_out_y = np.linspace((height_in - height_out) / 2, height_out, out_nodes)
    pos = dict()
    pos.update((n, (1, i)) for i, n in zip(height_in_y, X))  # put nodes from X at x=1
    pos.update((n, (3, i)) for i, n in zip(height_out_y, Y))  # put nodes from Y at x=2
    ax.axis('off')
    ax.set_xlim(-1,4)
    ax.set_title(title)
    nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes), node_color='r', node_size=50, ax=ax)
    nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes, in_nodes + out_nodes), node_color='b', node_size=50, ax=ax)
    for edge in g.edges():
        nx.draw_networkx_edges(g, pos, edgelist=[edge], width=weight[edge[0], edge[1] - in_nodes] * 1.5, ax=ax)
    nx.draw_networkx_labels(g, pos, {i:label + '  ' for i,label in enumerate(M)},horizontalalignment='right', font_size=8, ax=ax)
    nx.draw_networkx_labels(g, pos, {i+in_nodes:'  ' + label for i,label in enumerate(N)},horizontalalignment='left', font_size=8, ax=ax) 
开发者ID:dmlc,项目名称:dgl,代码行数:25,代码来源:viz.py

示例3: plot_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def plot_edges(axs, adata, basis, edges_width, edges_color, neighbors_key=None):
    import networkx as nx

    if not isinstance(axs, cabc.Sequence):
        axs = [axs]

    if neighbors_key is None:
        neighbors_key = 'neighbors'
    if neighbors_key not in adata.uns:
        raise ValueError('`edges=True` requires `pp.neighbors` to be run before.')
    neighbors = NeighborsView(adata, neighbors_key)
    g = nx.Graph(neighbors['connectivities'])
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        for ax in axs:
            edge_collection = nx.draw_networkx_edges(
                g,
                adata.obsm['X_' + basis],
                ax=ax,
                width=edges_width,
                edge_color=edges_color,
            )
            edge_collection.set_zorder(-2)
            edge_collection.set_rasterized(settings._vector_friendly) 
开发者ID:theislab,项目名称:scanpy,代码行数:26,代码来源:_utils.py

示例4: draw_transmat_graph_inner

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def draw_transmat_graph_inner(G, edge_threshold=0, lw=1, ec='0.2', node_size=15):

    num_states = G.number_of_nodes()

    edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]
    edgewidth = np.array(edgewidth)
    edgewidth[edgewidth<edge_threshold] = 0

    npos=circular_layout(G, scale=1, direction='CW')

    nx.draw_networkx_edges(G, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)

    nx.draw_networkx_nodes(G, npos, node_size=node_size, node_color='k',alpha=1.0)
    ax = plt.gca()
    ax.set_aspect('equal')

    return ax 
开发者ID:nelpy,项目名称:nelpy,代码行数:19,代码来源:graph.py

示例5: draw_transmat_graph_outer

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def draw_transmat_graph_outer(Go, Gi, edge_threshold=0, lw=1, ec='0.2', nc='k', node_size=15):

    num_states = Go.number_of_nodes()

    edgewidth = [ d['weight'] for (u,v,d) in Go.edges(data=True)]
    edgewidth = np.array(edgewidth)
    edgewidth[edgewidth<edge_threshold] = 0

    npos=double_circular_layout(Gi, scale=1, direction='CW')

    nx.draw_networkx_edges(Go, npos, alpha=1.0, width=edgewidth*lw, edge_color=ec)

    nx.draw_networkx_nodes(Go, npos, node_size=node_size, node_color=nc,alpha=1.0)

    ax = plt.gca()
    ax.set_aspect('equal')

    return ax 
开发者ID:nelpy,项目名称:nelpy,代码行数:20,代码来源:graph.py

示例6: plot_network

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def plot_network(self, G, status, pos=None, nodelist=None, colordict={'S':'#009a80','I':'#ff2020', 'R':'gray'}, **nx_kwargs):
        r'''
        Plots the network in the axes self.networkx_ax.  Nodes are colored according to their status.
        if no ordered nodelist is provided, then the nodes are plotted so that 'I' nodes appear on top, while the order of the 'S' and 'R' nodes is random.  When the network is very dense this highlights 'I' nodes and allows the final state to more accurately represent the proportion of nodes having each status.
        '''
        colorlist = []
        if pos is None:
            pos = nx.spring_layout(G)
        if nodelist is None:
            nodelist = list(G.nodes())
            I_nodes = [node for node in nodelist if status[node] == 'I']
            other_nodes = [node for node in nodelist if status[node]!='I']
            random.shuffle(other_nodes)
            nodelist = other_nodes + I_nodes
            edgelist = list(G.edges())
        else:
            nodeset = set(nodelist)
            edgelist = [edge for edge in G.edges() if edge[0] in nodeset and edge[1] in nodeset]
        for node in nodelist:
            colorlist.append(colordict[status[node]])
        nx.draw_networkx_edges(G, pos, edgelist=edgelist, ax = self.network_axes, **nx_kwargs)
        nx.draw_networkx_nodes(G, pos, nodelist = nodelist, node_color=colorlist, ax=self.network_axes, **nx_kwargs)
        self.network_axes.set_xticks([])
        self.network_axes.set_yticks([]) 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:26,代码来源:class_based_visualization.py

示例7: _initialize

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def _initialize(self):
        initial_status = EoN.get_statuses(self.G, self.node_history, self.frame_times[0])
        colorlist = [self.colordict[initial_status[node]] for node in self.nodelist]

        nodeset = {node for node in self.nodelist}
        edgelist = [edge for edge in self.G.edges() if edge[0] in nodeset and edge[1] in nodeset]
        nx.draw_networkx_edges(self.G, pos=self.pos, edgelist=edgelist, ax = self.network_axes)

        drawn_nodes = nx.draw_networkx_nodes(self.G, pos=self.pos, ax = self.network_axes, nodelist = self.nodelist, color=colorlist, **self.kwargs)
        Inodelist = [node for node in self.nodelist if initial_status[node] == 'I']
        drawn_I = [nx.draw_networkx_nodes(self.G, pos=self.pos, nodelist=Inodelist, color = self.colordict['I'], ax = self.network_axes, **self.kwargs)]

        self.network_axes.set_xticks([])
        self.network_axes.set_yticks([])
        
        time_markers = [None for ax in self.timeseries_axi]
        self._highlight_time(self.frame_times[0], time_markers)
        return drawn_nodes, drawn_I, time_markers 
开发者ID:springer-math,项目名称:Mathematics-of-Epidemics-on-Networks,代码行数:20,代码来源:class_based_visualization.py

示例8: plot_subgraph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def plot_subgraph(self, region_start, region_stop, seq_name, neighbours=0):
		"""
		Return a plot of a sub-graph from a defined region with positions relative to some of the sequences.
		:param region_start: Start position (bp)
		:param region_stop: Stop position (bp)
		:param seq_name: Sequence ID that the bp positions are relative to.
		:param neighbours: Number of neighbours to be included. Currently testing, only 1 level available.
		:return: Plots a netowrkx + matplotlib figure of the region subgraph.
		"""

		sub_graph = extract_region_subgraph(self, region_start, region_stop, seq_name, neighbours=neighbours)
		pos = nx.spring_layout(sub_graph)
		nx.draw_networkx_nodes(sub_graph, pos, cmap=plt.get_cmap('jet'), node_size=300)
		nx.draw_networkx_labels(sub_graph, pos)
		nx.draw_networkx_edges(sub_graph, pos, arrows=True)
		plt.show() 
开发者ID:jambler24,项目名称:GenGraph,代码行数:18,代码来源:gengraph.py

示例9: replay

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def replay(self, graph):
        """Draw the given graph."""
        fig, ax = plt.subplots(frameon=False)  # pylint:disable=invalid-name
        plt.subplots_adjust(left=0, right=1, top=1, bottom=0)

        node_pos = graph.node_coordinates

        def _update(num):
            ax.clear()

            fig.canvas.set_window_title(f'{graph.name} - Iteration ({num+1}/{len(self.__edge_colors)})')

            nodes_artist = nx.draw_networkx_nodes(graph.networkx_graph, pos=node_pos, ax=ax, node_color=self.__node_color)
            labels_artist = nx.draw_networkx_labels(graph.networkx_graph, pos=node_pos, ax=ax)
            edges_artist = nx.draw_networkx_edges(graph.networkx_graph, pos=node_pos, width=self.__edge_widths[num], edge_color=self.__edge_colors[num], ax=ax)

            return nodes_artist, labels_artist, edges_artist

        _ = animation.FuncAnimation(fig, _update, frames=len(self.__edge_colors), interval=self.__interval, repeat=self.__continuous)
        plt.show() 
开发者ID:HaaLeo,项目名称:swarmlib,代码行数:22,代码来源:visualizer.py

示例10: draw_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def draw_graph(self):
        nx.draw_shell(self.G, with_labels=True, font_weight='bold')

        # pos = graphviz_layout(self.G)
        # plt.axis('off')
        # nx.draw_networkx_nodes(self.G,pos,node_color='g',alpha = 0.8)
        # nx.draw_networkx_edges(self.G,pos,edge_color='b',alpha = 0.6)
        # nx.draw_networkx_edge_labels(self.G,pos,edge_labels = \
        # nx.get_edge_attributes(self.G,'weight'))
        # nx.draw_networkx_labels(self.G,pos) # node lables

        plt.savefig('graph.png') 
开发者ID:gcallah,项目名称:indras_net,代码行数:14,代码来源:good_structure.py

示例11: draw_adjacency_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def draw_adjacency_graph(adjacency_matrix,
                         node_color=None,
                         size=10,
                         layout='graphviz',
                         prog='neato',
                         node_size=80,
                         colormap='autumn'):
    """draw_adjacency_graph."""
    graph = nx.from_scipy_sparse_matrix(adjacency_matrix)

    plt.figure(figsize=(size, size))
    plt.grid(False)
    plt.axis('off')

    if layout == 'graphviz':
        pos = nx.graphviz_layout(graph, prog=prog)
    else:
        pos = nx.spring_layout(graph)

    if len(node_color) == 0:
        node_color = 'gray'
    nx.draw_networkx_nodes(graph, pos,
                           node_color=node_color,
                           alpha=0.6,
                           node_size=node_size,
                           cmap=plt.get_cmap(colormap))
    nx.draw_networkx_edges(graph, pos, alpha=0.5)
    plt.show()


# draw a whole set of graphs:: 
开发者ID:fabriziocosta,项目名称:EDeN,代码行数:33,代码来源:__init__.py

示例12: malt_demo

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
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() 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:43,代码来源:dependencygraph.py

示例13: plot

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
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 call graph to plot
    """
    from androguard.core.analysis.analysis import ExternalMethod
    import matplotlib.pyplot as plt
    import networkx as nx
    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:amimo,项目名称:dcc,代码行数:33,代码来源:main.py

示例14: _draw_edges

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def _draw_edges(self, edgelist, **kwargs):
        edge_labels = kwargs.get('edge_labels', False)
        if edge_labels is not False:
            if edge_labels is True:
                edge_labels = {(f, t): '({},{})'.format(f, t) for f, t in edgelist}
            self._draw_edge_labels(edge_labels)
        return nx.draw_networkx_edges(self._G, self._pos, edgelist=edgelist, **kwargs) 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:9,代码来源:__init__.py

示例15: weight_animate

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import draw_networkx_edges [as 别名]
def weight_animate(i):
    ax.cla()
    ax.axis('off')
    ax.set_title("Routing: %d  " % i)
    dm = dist_list[i]
    nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes), node_color='r', node_size=100, ax=ax)
    nx.draw_networkx_nodes(g, pos, nodelist=range(in_nodes, in_nodes + out_nodes), node_color='b', node_size=100, ax=ax)
    for edge in g.edges():
        nx.draw_networkx_edges(g, pos, edgelist=[edge], width=dm[edge[0], edge[1] - in_nodes] * 1.5, ax=ax) 
开发者ID:dmlc,项目名称:dgl,代码行数:11,代码来源:2_capsule.py


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