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


Python nx_agraph.graphviz_layout方法代碼示例

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


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

示例1: _layoutBlockGraph

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def _layoutBlockGraph(self):
        # note that graphviz expects sizes in inches, so we scale them back
        self._setGraphNodeSizes(1. / self.GRAPHVIZ_SCALE_FACTOR)

        # dot is for directed graphs
        layout = graphviz_layout(self.blockGraph, prog='dot')

        layout = self._fixGraphvizLayout(layout)

        for blockAddr in self.blockAddrs:
            # this both updates the HTML element, and the graph node's
            # x and y attributes
            self._setBlockPos(blockAddr, layout[blockAddr])

        # now set node sizes for edge layout algo
        self._setGraphNodeSizes(scalingFactor=1.0)

        layoutAlgo = _EdgeLayoutAlgo(self.blockGraph)
        edgePaths = layoutAlgo.doLayout()

        for b1Addr, b2Addr in self.blockGraph.edges_iter():
            self._setEdgePath(b1Addr, b2Addr, edgePaths[b1Addr, b2Addr])

        self._updateSceneRect(edgePaths) 
開發者ID:sapir,項目名稱:sonare,代碼行數:26,代碼來源:graph.py

示例2: draw_wstate_tree

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

示例3: recalculate_positions

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def recalculate_positions(self, prog='sfdp', *args, **kwargs):
        try:
            self.positions = graphviz_layout(self._G, prog=prog, *args, **kwargs)
        except ImportError:
            import warnings
            warnings.warn("Unable to use graphviz, please install pygraphviz. Using networkx spring layout by default")
            self.positions = nx.spring_layout(self._G, *args, **kwargs)
        return self.positions 
開發者ID:power-system-simulation-toolbox,項目名稱:psst,代碼行數:10,代碼來源:__init__.py

示例4: main

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def main():
    # Create a directed graph
    G = nx.DiGraph()

    # An example
    l=[ ('a','b'),
        ('b','c'),
        ('c','d'),
        ('d','e'),
        ('e','f'),
        ('w','x'),
        ('w','t'),
        ('t','q'),
        ('q','r'),
        ('q','u')]

    # Build up a graph
    for t in l:
        G.add_edge(t[0], t[1])

    # Plot trees
    pos = graphviz_layout(G, prog='dot')
    nx.draw(G, pos, with_labels=True, arrows=False)

    plt.savefig('draw_trees_with_pygraphviz.png', bbox_inches='tight')   
    plt.show() 
開發者ID:sparkandshine,項目名稱:complex_network,代碼行數:28,代碼來源:draw_trees_with_pygraphviz.py

示例5: plot_nx

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def plot_nx(bn,**kwargs):
	"""
	Draw BayesNet object from networkx engine
	"""
	g = nx.DiGraph(bn.E)
	pos = graphviz_layout(g,'dot')
	#node_size=600,node_color='w',with_labels=False
	nx.draw_networkx(g,pos=pos, **kwargs)
	plt.axis('off')
	plt.show() 
開發者ID:ncullen93,項目名稱:pyBN,代碼行數:12,代碼來源:plot.py

示例6: plot_network_with_results

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def plot_network_with_results(psstc, model, time=0):
    G = create_network(psstc)

    fig, axs = plt.subplots(1, 1, figsize=(12, 9))
    ax = axs

    line_color_dict = dict()
    hour = 0
    for i, b in branch_df.iterrows():
        if model.ThermalLimit[i] != 0:
            line_color_dict[(b['F_BUS'], b['T_BUS'])] = round(abs(model.LinePower[i, hour].value / model.ThermalLimit[i]), 2)
        else:
            line_color_dict[(b['F_BUS'], b['T_BUS'])] = 0

    gen_color_dict = dict()
    hour = 0
    for i, g in generator_df.iterrows():
        gen_color_dict[(i, g['GEN_BUS'])] = round(abs(model.PowerGenerated[i, hour].value / model.MaximumPowerOutput[i]), 2)

    color_dict = line_color_dict.copy()
    color_dict.update(gen_color_dict)

    edge_color = list()

    for e in G.edges():
        try:
            edge_color.append( color_dict[(e[0], e[1])] )
        except KeyError:
            edge_color.append( color_dict[(e[1], e[0])] )

    ax.axis('off')
    pos = graphviz_layout(G, prog='sfdp')
    nx.draw_networkx_nodes(G, pos, list(generator_df.index),)
    nx.draw_networkx_nodes(G, pos, list(bus_df.index), node_color='black',)
    edges = nx.draw_networkx_edges(G, pos, edge_color=edge_color, edge_cmap=cmap, width=3)
    nx.draw_networkx_edge_labels(G, pos, edge_labels=color_dict)

    divider = make_axes_locatable(ax)
    cax = divider.append_axes("left", size="5%", pad=0.05)
    cb = plt.colorbar(edges, cax=cax)
    cax.yaxis.set_label_position('left')
    cax.yaxis.set_ticks_position('left')
    # cb.set_label('Voltage (V)') 
開發者ID:power-system-simulation-toolbox,項目名稱:psst,代碼行數:45,代碼來源:plot.py

示例7: __init__

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def __init__(self, name, table, rootlane='timepoint', shift=None, log2=True, posgl=False, csv=False, groups=True):
        """
        Initializes the class by providing the the common name ('name') of .gexf and .json files produced by
        e.g. ParseAyasdiGraph(), the name of the file containing the filtered raw data ('table'), as produced by
        Preprocess.save(), and the name of the column that contains sampling time points. Optional argument
        'shift' can be an integer n specifying that the first n columns of the table should be ignored, or a
        list of columns that should only be considered. If optional argument 'log2' is False, it is assumed that
        the filtered raw data is in units of TPM instead of log_2(1+TPM). When optional argument 'posgl' is False,
        a files name.posg and name.posgl are generated with the positions of the graph nodes for visualization.
        When 'posgl' is True, instead of generating new positions, the positions stored in files name.posg and
        name.posgl are used for visualization of the topological graph.
        """
        UnrootedGraph.__init__(self, name, table, shift, log2, posgl, csv, groups)
        self.rootlane = rootlane
        self.root, self.leaf = self.find_root(self.get_dendrite())
        self.g3, self.dicdend = self.dendritic_graph()
        self.edgesize = []
        self.dicedgesize = {}
        self.edgesizeprun = []
        self.nodesize = []
        self.dicmelisa = {}
        self.nodesizeprun = []
        self.dicmelisaprun = {}
        for ee in self.g3.edges():
            yu = self.dicdend[int(ee[0].split('_')[0])][int(ee[0].split('_')[1])]
            yu2 = self.dicdend[int(ee[1].split('_')[0])][int(ee[1].split('_')[1])]
            self.edgesize.append(self.gl.subgraph(list(yu)+list(yu2)).number_of_edges()-self.gl.subgraph(yu).number_of_edges()
                                 - self.gl.subgraph(yu2).number_of_edges())
            self.dicedgesize[ee] = self.edgesize[-1]
        for ee in self.g3.nodes():
            lisa = []
            for uu in self.dicdend[int(ee.split('_')[0])][int(ee.split('_')[1])]:
                lisa += self.dic[uu]
            self.nodesize.append(len(set(lisa)))
            self.dicmelisa[ee] = set(lisa)
        try:
            from networkx.drawing.nx_agraph import graphviz_layout
            self.posg3 = graphviz_layout(self.g3, 'sfdp')
        except:
            self.posg3 = networkx.spring_layout(self.g3)
        self.dicdis = self.get_distroot(self.root)
        pel2, tol = self.get_gene(self.rootlane, ignore_log=True)
        self.pel = numpy.array([pel2[m] for m in self.pl])*tol
        dr2 = self.get_distroot(self.root)
        self.dr = numpy.array([dr2[m] for m in self.pl])
        self.po = scipy.stats.linregress(self.pel, self.dr) 
開發者ID:CamaraLab,項目名稱:scTDA,代碼行數:48,代碼來源:main.py

示例8: render

# 需要導入模塊: from networkx.drawing import nx_agraph [as 別名]
# 或者: from networkx.drawing.nx_agraph import graphviz_layout [as 別名]
def render(self, mode='human', close=False):
        if self.simple_render:
            observation = np.zeros((20, 20*self.chain_length))
            observation[:, self.state*20:(self.state+1)*20] = 255
            return observation
        else:
            # lazy loading of networkx and matplotlib to allow using the environment without installing them if
            # necessary
            import networkx as nx
            from networkx.drawing.nx_agraph import graphviz_layout
            import matplotlib.pyplot as plt

            if not hasattr(self, 'G'):
                self.states = list(range(self.chain_length))
                self.G = nx.DiGraph(directed=True)
                for i, origin_state in enumerate(self.states):
                    if i < self.chain_length - 1:
                        self.G.add_edge(origin_state,
                                        origin_state + 1,
                                        weight=0.5)
                    if i > 0:
                        self.G.add_edge(origin_state,
                                        origin_state - 1,
                                        weight=0.5, )
                    if i == 0 or i < self.chain_length - 1:
                        self.G.add_edge(origin_state,
                                        origin_state,
                                        weight=0.5, )

            fig = plt.gcf()
            if np.all(fig.get_size_inches() != [10, 2]):
                fig.set_size_inches(5, 1)
            color = ['y']*(len(self.G))
            color[self.state] = 'r'
            options = {
                'node_color': color,
                'node_size': 50,
                'width': 1,
                'arrowstyle': '-|>',
                'arrowsize': 5,
                'font_size': 6
            }
            pos = graphviz_layout(self.G, prog='dot', args='-Grankdir=LR')
            nx.draw_networkx(self.G, pos, arrows=True, **options)
            fig.canvas.draw()
            data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
            data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
            return data 
開發者ID:NervanaSystems,項目名稱:coach,代碼行數:50,代碼來源:exploration_chain.py


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