當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.draw_networkx_edge_labels方法代碼示例

本文整理匯總了Python中networkx.draw_networkx_edge_labels方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.draw_networkx_edge_labels方法的具體用法?Python networkx.draw_networkx_edge_labels怎麽用?Python networkx.draw_networkx_edge_labels使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.draw_networkx_edge_labels方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: plot_alerts

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [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: plot

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def plot(self, file_path: str):
        try:
            import matplotlib.pyplot as plt
        except ImportError as err:
            raise('matplotlib not installed. Failed at: {}', err)

        try:
            pos = nx.nx_agraph.graphviz_layout(self.directed)
            nx.draw(
                self.directed,
                pos=pos,
                node_size=1200,
                node_color='lightblue',
                linewidths=0.25,
                font_size=8,
                font_weight='bold',
                with_labels=True,
                dpi=5000
            )
            # edge_labels = nx.get_edge_attributes(self.directed, name='attr_dict')
            # nx.draw_networkx_edge_labels(self.directed, pos=pos, edge_labels=edge_labels)
            plt.savefig(file_path)
        except IOError as err:
            raise('Could not create plot image: {}', err) 
開發者ID:leopepe,項目名稱:GOApy,代碼行數:26,代碼來源:Planner.py

示例3: draw_wstate_tree

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def draw_wstate_tree(svm):
    import matplotlib.pyplot as plt
    import networkx as nx
    from networkx.drawing.nx_agraph import write_dot, graphviz_layout

    G = nx.DiGraph()
    pending_list = [svm.root_wstate]
    while len(pending_list):
        root = pending_list.pop()
        for trace, children in root.trace_to_children.items():
            for c in children:
                G.add_edge(repr(root), repr(c), label=trace)
                pending_list.append(c)
    # pos = nx.spring_layout(G)
    pos = graphviz_layout(G, prog='dot')
    edge_labels = nx.get_edge_attributes(G, 'label')
    nx.draw(G, pos)
    nx.draw_networkx_edge_labels(G, pos, edge_labels, font_size=8)
    nx.draw_networkx_labels(G, pos, font_size=10)
    plt.show() 
開發者ID:eth-sri,項目名稱:ilf,代碼行數:22,代碼來源:svm_utils.py

示例4: print_graph_nx

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def print_graph_nx(vertices, edges, print_dist=False):
  import networkx as nx
  G=nx.DiGraph()
  labels = []

  for v in vertices:
    G.add_node(v)

  for v in vertices:
    for e in edges:
      G.add_edge(e[0], e[1], weight=int(e[2]))
      #labels += [(e[0], e[1]), e[2]]

  print("Nodes of graph: ")
  print(G.nodes())
  print("Edges of graph: ")
  print(G.edges())

  nx.draw(G, with_labels=True, node_color='y')
  #nx.draw_networkx_edge_labels(G,labels)
  plt.savefig("simulation_graph.png") # save as png
  plt.show() 
開發者ID:djgroen,項目名稱:flee-release,代碼行數:24,代碼來源:analyze_graph.py

示例5: draw_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def draw_graph(graph, output):
        """If matplotlib is available, draw the given graph to output file"""
        try:
            layout = nx.spring_layout(graph)
            metrics = {
                (src, dst): data['metric']
                for src, dst, data in graph.edges_iter(data=True)
            }
            nx.draw_networkx_edge_labels(graph, layout, edge_labels=metrics)
            nx.draw(graph, layout, node_size=20)
            nx.draw_networkx_labels(graph, layout,
                                    labels={n: n for n in graph})
            if os.path.exists(output):
                os.unlink(output)
            plt.savefig(output)
            plt.close()
            log.debug('Graph of %d nodes saved in %s', len(graph), output)
        except:
            pass 
開發者ID:Fibbing,項目名稱:FibbingNode,代碼行數:21,代碼來源:igp_graph.py

示例6: draw_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [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

示例7: _draw_edge_labels

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def _draw_edge_labels(self, edge_labels, **kwargs):
        pos = kwargs.pop('pos', self._pos)
        return nx.draw_networkx_edge_labels(self._G, pos, edge_labels=edge_labels, **kwargs) 
開發者ID:power-system-simulation-toolbox,項目名稱:psst,代碼行數:5,代碼來源:__init__.py

示例8: draw_and_save_topology

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def draw_and_save_topology(graph: nx.Graph, edge_labels: List[Dict[Tuple[str, str], str]]) -> None:
    plt.figure(1, figsize=(12, 12))
    pos = nx.spring_layout(graph)
    nx.draw_networkx(graph, pos, node_size=1300, node_color='orange')
    nx.draw_networkx_edge_labels(graph, pos, edge_labels=edge_labels[0], label_pos=0.8)
    nx.draw_networkx_edge_labels(graph, pos, edge_labels=edge_labels[1], label_pos=0.2)
    filename = "topology.png"
    plt.savefig(filename)
    logger.info("The network topology diagram has been saved to %r", filename) 
開發者ID:dmfigol,項目名稱:network-programmability-stream,代碼行數:11,代碼來源:main.py

示例9: visualize

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def visualize(self):
        # import matplotlib.pyplot as plt
        pos = nx.spring_layout(self.graph_state)
        edge_labels = {e: self.graph_state.edges[e]['rel'] for e in self.graph_state.edges}
        print(edge_labels)
        nx.draw_networkx_edge_labels(self.graph_state, pos, edge_labels)
        nx.draw(self.graph_state, pos=pos, with_labels=True, node_size=200, font_size=10)
        #plt.show() 
開發者ID:rajammanabrolu,項目名稱:KG-A2C,代碼行數:10,代碼來源:representations.py

示例10: _plot_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def _plot_graph(graph, axis, weights=None, display_edge_labels=True):
    """Plot graph using networkx."""
    pos = nx.circular_layout(graph)
    nx.draw_circular(graph, with_labels=True, node_size=600, alpha=1.0,
                     ax=axis, node_color='Gainsboro', hold=True, font_size=14,
                     font_weight='bold')
    if display_edge_labels:
        edge_labels = nx.get_edge_attributes(graph, weights)
        nx.draw_networkx_edge_labels(graph, pos, edge_labels=edge_labels,
                                     font_size=13)  # font_weight='bold' 
開發者ID:pwollstadt,項目名稱:IDTxl,代碼行數:12,代碼來源:visualise_graph.py

示例11: plot_mute_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def plot_mute_graph():
    """Plot MuTE example network.

    Network of 5 AR-processes, which is used as an example the paper
    on the MuTE toolbox (Montalto, PLOS ONE, 2014, eq. 14). The
    network consists of five autoregressive (AR) processes with model
    orders 2 and les and the following (non-linear) couplings:

        >>> 0 -> 1, u = 2
        >>> 0 -> 2, u = 3
        >>> 0 -> 3, u = 2 (non-linear)
        >>> 3 -> 4, u = 1
        >>> 4 -> 3, u = 1

    Returns:
        Figure handle
            Figure object from the matplotlib package
    """
    graph = nx.DiGraph()
    graph.add_nodes_from(np.arange(5))
    # graph.add_edges_from([(0, 1), (0, 2), (0, 3), (3, 4), (4, 3)])
    graph.add_weighted_edges_from([(0, 1, 2), (0, 2, 3), (0, 3, 2), (3, 4, 1),
                                   (4, 3, 1)], weight='delay')
    pos = {
        0: np.array([1, 1]),
        1: np.array([0, 2]),
        2: np.array([0, 0]),
        3: np.array([2, 1]),
        4: np.array([3, 1]),
    }
    fig = plt.figure()
    nx.draw(graph, pos=pos, with_labels=True, node_size=900, alpha=1.0,
            node_color='cadetblue', font_weight='bold',
            edge_color=['r', 'k', 'r', 'k', 'k'], hold=True)
    nx.draw_networkx_edge_labels(graph, pos=pos)
    plt.text(2, 0.1, 'non-linear interaction in red')
    # see here for an example on how to plot edge labels:
    # http://stackoverflow.com/questions/10104700/how-to-set-networkx-edge-labels-offset-to-avoid-label-overlap
    return fig 
開發者ID:pwollstadt,項目名稱:IDTxl,代碼行數:41,代碼來源:visualise_graph.py

示例12: showTask

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def showTask(task, root="ROOT()", filename="task.dot"):
    import matplotlib.pyplot as plt

    g = nx.DiGraph()

    nodes = [root]
    visited = set()
    nodelist = []

    print(root)
    print(task.nodeSummary())

    while len(nodes) > 0:
        node = nodes.pop()
        visited.add(node)
        children = task.children[node]
        print("NODE =", node, "CHILDREN =")
        weights = task.weights[node]
        if len(weights) > 0:
            for child, wt in zip(children, weights):
                print("\t",child,"weight =", wt)
                g.add_edge(node, child, weight=int(wt))
                nodelist.append(child)
                if child not in visited:
                    print("\t\tadding", child)
                    nodes.append(child)
        elif len(children) > 0:
            raise RuntimeError('weights not initialized')

    pos = nx.nx_agraph.graphviz_layout(g, prog="dot")
    nx.draw_networkx_edges(g, pos, width=1.0, alpha=1., arrows=False)
    nx.draw(g, pos, prog='dot', node_size=1000, nodelist=nodelist,
            width=1.0, alpha=1., arrows=True, with_labels=True,)
    labels = nx.get_edge_attributes(g,'weight')
    nx.draw_networkx_edge_labels(g,pos,edge_labels=labels)
    #a = nx.nx_agraph.to_agraph(g)
    #a.draw('ex.png', prog='dot')
    plt.axis('off')
    plt.show() 
開發者ID:jhu-lcsr,項目名稱:costar_plan,代碼行數:41,代碼來源:show_task.py

示例13: plot_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def plot_graph(G, out_file=None, node_size=1500, font_size=10,
				node_and_labels=None, edge_and_labels=None):
	"""
	plot a graph
	"""

	pos = nx.get_node_attributes(G, 'pos')
	if not pos:
		pos = nx.spring_layout(G)

	nx.draw_networkx(G, pos, node_size=node_size, 
						node_color='w', 
						edge_color='k', 
						labels = node_and_labels,
						font_size=font_size,
						font_color='r',
						arrows=True,
						with_labels=True)

	plt.axis('off')	

	if edge_and_labels:
		nx.draw_networkx_edge_labels(G, pos, 
										edge_labels=edge_and_labels, 
										font_color='r',
										label_pos=0.4, 
										alpha=0.0)

	if out_file:
		plt.savefig(out_file, bbox_inches='tight')

	plt.show() 
開發者ID:sparkandshine,項目名稱:complex_network,代碼行數:34,代碼來源:plotnxgraph.py

示例14: plot

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
def plot(self, density=1.0):
        """Plots a network diagram from (triple) nodes and edges in the KB.

        :param float density: Probability (0-1) that a given edge will be plotted, \
        useful to thin out dense graphs for visualization."""
        edgelist = [e for e in self.G.edges(data=True) if random.random() < density]
        newg = nx.DiGraph(edgelist)
        pos = nx.spring_layout(newg)
        plt.figure(1,figsize=(12,12))
        nx.draw_networkx_nodes(newg, pos, node_size=200)
        nx.draw_networkx_edges(newg, pos, edgelist=edgelist, width=1, font_size=8)
        nx.draw_networkx_labels(newg, pos, font_size=10, font_family='sans-serif')
        nx.draw_networkx_edge_labels(newg, pos)
        plt.axis('off')
        plt.show() 
開發者ID:tomgrek,項目名稱:zincbase,代碼行數:17,代碼來源:zincbase.py

示例15: _build_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_networkx_edge_labels [as 別名]
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
######################################### 
開發者ID:khundman,項目名稱:marve,代碼行數:39,代碼來源:Measurements.py


注:本文中的networkx.draw_networkx_edge_labels方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。