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


Python networkx.draw_circular方法代碼示例

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


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

示例1: test_draw

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def test_draw(self):
        try:
            N=self.G
            nx.draw_spring(N)
            plt.savefig("test.ps")
            nx.draw_random(N)
            plt.savefig("test.ps")
            nx.draw_circular(N)
            plt.savefig("test.ps")
            nx.draw_spectral(N)
            plt.savefig("test.ps")
            nx.draw_spring(N.to_directed())
            plt.savefig("test.ps")
        finally:
            try:
                os.unlink('test.ps')
            except OSError:
                pass 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:20,代碼來源:test_pylab.py

示例2: test_draw

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def test_draw(self):
        try:
            functions = [nx.draw_circular,
                         nx.draw_kamada_kawai,
                         nx.draw_planar,
                         nx.draw_random,
                         nx.draw_spectral,
                         nx.draw_spring,
                         nx.draw_shell]
            options = [{
                'node_color': 'black',
                'node_size': 100,
                'width': 3,
            }]
            for function, option in itertools.product(functions, options):
                function(self.G, **option)
                plt.savefig('test.ps')

        finally:
            try:
                os.unlink('test.ps')
            except OSError:
                pass 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:25,代碼來源:test_pylab.py

示例3: test_draw

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def test_draw(self):
        try:
            functions = [nx.draw_circular,
                         nx.draw_kamada_kawai,
                         nx.draw_random,
                         nx.draw_spectral,
                         nx.draw_spring,
                         nx.draw_shell]
            options = [{
                           'node_color': 'black',
                           'node_size': 100,
                           'width': 3,
                       }]
            for function, option in itertools.product(functions, options):
                function(self.G, **option)
                plt.savefig('test.ps')

        finally:
            try:
                os.unlink('test.ps')
            except OSError:
                pass 
開發者ID:aws-samples,項目名稱:aws-kube-codesuite,代碼行數:24,代碼來源:test_pylab.py

示例4: display_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def display_graph(variables, relations):
    """
    Display the variables and relation as a graph, using networkx and
    matplotlib.

    Parameters
    ----------

    variables: list
        a list of Variable objets
    relations: list
        a list of Relation objects
    """
    graph = as_networkx_graph(variables, relations)

    # Do not crash if matplotlib is not installed
    try:
        import matplotlib.pyplot as plt

        nx.draw_networkx(graph, with_labels=True)
        # nx.draw_random(graph)
        # nx.draw_circular(graph)
        # nx.draw_spectral(graph)
        plt.show()
    except ImportError:
        print("ERROR: cannot display graph, matplotlib is not installed") 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:28,代碼來源:graphs.py

示例5: update_net

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def update_net(self, node, edge, direction):
        plt.figure(1)
        # self.lg.info("Update net", node, edge, direction)
        if node:
            self.net_labels[node] = node
            if node in self.Type and self.Type[node] == "MP":
                if direction == "IN":
                    self.G.add_node(node, behaviour='malicious')
                else:
                    self.lg.info("simulator: {} removed from graph (MP)".format(node))
                    self.G.remove_node(node)
                    del self.net_labels[node]
            elif node in self.Type and self.Type[node] == "M":
                if direction == "IN":
                    self.G.add_node(node, behaviour='monitor')
                else:
                    self.G.remove_node(node)
                    del self.net_labels[node]
            else:
                if direction == "IN":
                    self.G.add_node(node, behaviour='peer')
                else:
                    self.G.remove_node(node)
                    del self.net_labels[node]
        else:
            if edge[0] in self.G.nodes() and edge[1] in self.G.nodes():
                if direction == "IN":
                    self.G.add_edge(*edge, color='#000000')
                else:
                    self.G.add_edge(*edge, color='r')

        self.net_figure.clf()
        edges = self.G.edges()
        edge_color = [self.G[u][v]['color'] for u, v in edges]
        node_color = [self.color_map[self.G.node[node]['behaviour']] for node in self.G]
        self.net_figure.suptitle("Overlay Network of the Team", size=16)
        nx.draw_circular(self.G, node_color=node_color, node_size=400, edge_color=edge_color, labels=self.net_labels,
                         font_size=10, font_weight='bold')
        self.net_figure.canvas.draw() 
開發者ID:P2PSP,項目名稱:simulator,代碼行數:41,代碼來源:play.py

示例6: _plot_graph

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

示例7: draw_graph_to_adjacency_matrix

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def draw_graph_to_adjacency_matrix(graph):
    """
    Draws the graph in circular format for easier debugging
    :param graph:
    :return:
    """
    dag = nx.DiGraph(graph)
    nx.draw_circular(dag, with_labels=True) 
開發者ID:automl,項目名稱:nasbench-1shot1,代碼行數:10,代碼來源:utils.py

示例8: plotGraph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def plotGraph(self, colorArrangement):
        """
        Plots the graph with the nodes colored according to the given color arrangement
        :param colorArrangement: a list of integers representing the suggested color arrangement fpo the nodes,
        one color per node in the graph
        """

        if len(colorArrangement) != self.__len__():
            raise ValueError("size of color list should be equal to ", self.__len__())

        # create a list of the unique colors in the arrangement:
        colorList = list(set(colorArrangement))

        # create the actual colors for the integers in the color list:
        colors = plt.cm.rainbow(np.linspace(0, 1, len(colorList)))

        # iterate over the nodes, and give each one of them its corresponding color:
        colorMap = []
        for i in range(self.__len__()):
            color = colors[colorList.index(colorArrangement[i])]
            colorMap.append(color)

        # plot the nodes with their labels and matching colors:
        nx.draw_kamada_kawai(self.graph, node_color=colorMap, with_labels=True)
        #nx.draw_circular(self.graph, node_color=color_map, with_labels=True)

        return plt


# testing the class: 
開發者ID:PacktPublishing,項目名稱:Hands-On-Genetic-Algorithms-with-Python,代碼行數:32,代碼來源:graphs.py

示例9: display_bipartite_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def display_bipartite_graph(variables, relations):
    """
    Display the variables and relation as a graph, using networkx and
    matplotlib.

    Parameters
    ----------
    variables: list
        a list of Variable objets
    relations: list
        a list of Relation objects
    """
    graph = as_networkx_bipartite_graph(variables, relations)

    # Do not crash if matplotlib is not installed
    try:
        import matplotlib.pyplot as plt

        pos = nx.drawing.spring_layout(graph)
        variables = set(n for n, d in graph.nodes(data=True) if d["bipartite"] == 0)
        factors = set(graph) - variables
        nx.draw_networkx_nodes(
            graph,
            pos=pos,
            with_labels=True,
            nodelist=variables,
            node_shape="o",
            node_color="b",
            label="variables",
            alpha=0.5,
        )
        nx.draw_networkx_nodes(
            graph,
            pos=pos,
            with_labels=True,
            nodelist=factors,
            node_shape="s",
            node_color="r",
            label="factors",
            alpha=0.5,
        )
        nx.draw_networkx_labels(graph, pos=pos)
        nx.draw_networkx_edges(graph, pos=pos)
        # nx.draw_random(graph)
        # nx.draw_circular(graph)
        # nx.draw_spectral(graph)
        plt.show()
    except ImportError:
        print("ERROR: cannot display graph, matplotlib is not installed") 
開發者ID:Orange-OpenSource,項目名稱:pyDcop,代碼行數:51,代碼來源:graphs.py

示例10: rollout_and_examine

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import draw_circular [as 別名]
def rollout_and_examine(self, model, num_samples):
        assert not model.training, 'You need to call model.eval().'

        num_total_size = 0
        num_valid_size = 0
        num_cycle = 0
        num_valid = 0
        plot_times = 0
        adj_lists_to_plot = []

        for i in range(num_samples):
            sampled_graph = model()
            if isinstance(sampled_graph, list):
                # When the model is a batched implementation, a list of
                # DGLGraph objects is returned. Note that with model(),
                # we generate a single graph as with the non-batched
                # implementation. We actually support batched generation
                # during the inference so feel free to modify the code.
                sampled_graph = sampled_graph[0]

            sampled_adj_list = dglGraph_to_adj_list(sampled_graph)
            adj_lists_to_plot.append(sampled_adj_list)

            graph_size = sampled_graph.number_of_nodes()
            valid_size = (self.v_min <= graph_size <= self.v_max)
            cycle = is_cycle(sampled_graph)

            num_total_size += graph_size

            if valid_size:
                num_valid_size += 1

            if cycle:
                num_cycle += 1

            if valid_size and cycle:
                num_valid += 1

            if len(adj_lists_to_plot) >= 4:
                plot_times += 1
                fig, ((ax0, ax1), (ax2, ax3)) = plt.subplots(2, 2)
                axes = {0: ax0, 1: ax1, 2: ax2, 3: ax3}
                for i in range(4):
                    nx.draw_circular(nx.from_dict_of_lists(adj_lists_to_plot[i]),
                                     with_labels=True, ax=axes[i])

                plt.savefig(self.dir + '/samples/{:d}'.format(plot_times))
                plt.close()

                adj_lists_to_plot = []

        self.num_samples_examined = num_samples
        self.average_size = num_total_size / num_samples
        self.valid_size_ratio = num_valid_size / num_samples
        self.cycle_ratio = num_cycle / num_samples
        self.valid_ratio = num_valid / num_samples 
開發者ID:dmlc,項目名稱:dgl,代碼行數:58,代碼來源:cycles.py


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