Python networkx.circular_layout() Examples
The following are 30
code examples of networkx.circular_layout().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_smoke_int(self): G = self.Gi vpos = nx.random_layout(G) vpos = nx.circular_layout(G) vpos = nx.planar_layout(G) vpos = nx.spring_layout(G) vpos = nx.fruchterman_reingold_layout(G) vpos = nx.fruchterman_reingold_layout(self.bigG) vpos = nx.spectral_layout(G) vpos = nx.spectral_layout(G.to_directed()) vpos = nx.spectral_layout(self.bigG) vpos = nx.spectral_layout(self.bigG.to_directed()) vpos = nx.shell_layout(G) if self.scipy is not None: vpos = nx.kamada_kawai_layout(G) vpos = nx.kamada_kawai_layout(G, dim=1)
Example #2
Source File: graph.py From nelpy with MIT License | 6 votes |
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
Example #3
Source File: networkx.py From hvplot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def draw_circular(G, **kwargs): """Draw networkx graph with circular layout. Parameters ---------- G : graph A networkx graph kwargs : optional keywords See hvplot.networkx.draw() for a description of optional keywords, with the exception of the pos parameter which is not used by this function. Returns ------- graph : holoviews.Graph or holoviews.Overlay Graph element or Graph and Labels """ return draw(G, pos=nx.circular_layout, **kwargs)
Example #4
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_empty_graph(self): G = nx.empty_graph() vpos = nx.random_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.circular_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.planar_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.bipartite_layout(G, G) assert_equal(vpos, {}) vpos = nx.spring_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.fruchterman_reingold_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.spectral_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.shell_layout(G, center=(1, 1)) assert_equal(vpos, {})
Example #5
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_smoke_int(self): G = self.Gi vpos = nx.random_layout(G) vpos = nx.circular_layout(G) vpos = nx.spring_layout(G) vpos = nx.fruchterman_reingold_layout(G) vpos = nx.fruchterman_reingold_layout(self.bigG) vpos = nx.spectral_layout(G) vpos = nx.spectral_layout(G.to_directed()) vpos = nx.spectral_layout(self.bigG) vpos = nx.spectral_layout(self.bigG.to_directed()) vpos = nx.shell_layout(G) if self.scipy is not None: vpos = nx.kamada_kawai_layout(G)
Example #6
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_smoke_string(self): G = self.Gs vpos = nx.random_layout(G) vpos = nx.circular_layout(G) vpos = nx.planar_layout(G) vpos = nx.spring_layout(G) vpos = nx.fruchterman_reingold_layout(G) vpos = nx.spectral_layout(G) vpos = nx.shell_layout(G) if self.scipy is not None: vpos = nx.kamada_kawai_layout(G) vpos = nx.kamada_kawai_layout(G, dim=1)
Example #7
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_scale_and_center_arg(self): sc = self.check_scale_and_center c = (4, 5) G = nx.complete_graph(9) G.add_node(9) sc(nx.random_layout(G, center=c), scale=0.5, center=(4.5, 5.5)) # rest can have 2*scale length: [-scale, scale] sc(nx.spring_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.spectral_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.circular_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.shell_layout(G, scale=2, center=c), scale=2, center=c) if self.scipy is not None: sc(nx.kamada_kawai_layout(G, scale=2, center=c), scale=2, center=c)
Example #8
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_default_scale_and_center(self): sc = self.check_scale_and_center c = (0, 0) G = nx.complete_graph(9) G.add_node(9) sc(nx.random_layout(G), scale=0.5, center=(0.5, 0.5)) sc(nx.spring_layout(G), scale=1, center=c) sc(nx.spectral_layout(G), scale=1, center=c) sc(nx.circular_layout(G), scale=1, center=c) sc(nx.shell_layout(G), scale=1, center=c) if self.scipy is not None: sc(nx.kamada_kawai_layout(G), scale=1, center=c)
Example #9
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_smoke_initial_pos_fruchterman_reingold(self): pos = nx.circular_layout(self.Gi) npos = nx.fruchterman_reingold_layout(self.Gi, pos=pos)
Example #10
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fixed_node_fruchterman_reingold(self): # Dense version (numpy based) pos = nx.circular_layout(self.Gi) npos = nx.fruchterman_reingold_layout(self.Gi, pos=pos, fixed=[(0, 0)]) assert_equal(tuple(pos[(0, 0)]), tuple(npos[(0, 0)])) # Sparse version (scipy based) pos = nx.circular_layout(self.bigG) npos = nx.fruchterman_reingold_layout(self.bigG, pos=pos, fixed=[(0, 0)]) for axis in range(2): assert_almost_equal(pos[(0, 0)][axis], npos[(0, 0)][axis])
Example #11
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_center_parameter(self): G = nx.path_graph(1) vpos = nx.random_layout(G, center=(1, 1)) vpos = nx.circular_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.planar_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.spring_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.fruchterman_reingold_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.spectral_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.shell_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1))
Example #12
Source File: test_layout.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_center_wrong_dimensions(self): G = nx.path_graph(1) assert_raises(ValueError, nx.random_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.circular_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.planar_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.spring_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.fruchterman_reingold_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.fruchterman_reingold_layout, G, dim=3, center=(1, 1)) assert_raises(ValueError, nx.spectral_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.spectral_layout, G, dim=3, center=(1, 1)) assert_raises(ValueError, nx.shell_layout, G, center=(1, 1, 1))
Example #13
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_smoke_empty_graph(self): G = [] vpos = nx.random_layout(G) vpos = nx.circular_layout(G) vpos = nx.spring_layout(G) vpos = nx.fruchterman_reingold_layout(G) vpos = nx.spectral_layout(G) vpos = nx.shell_layout(G) if self.scipy is not None: vpos = nx.kamada_kawai_layout(G)
Example #14
Source File: module_tree.py From msticpy with MIT License | 5 votes |
def plot_graph(call_graph: nx.Graph, size: Tuple[int, int] = (10, 10)): """ Plot circular graph using matplotlib. Parameters ---------- call_graph : nx.Graph The graph to plot. size : Tuple[int, int] size of plot, default is(10,10) """ # if circos: # c = CircosPlot( # call_graph, # node_color='degree', # node_grouping='degree', # node_order="degree", # node_labels=True, # fontsize="large", # node_label_layout="rotation", # figsize=(20,20) # ) # c.draw() # else: pos = nx.circular_layout(call_graph) nx.draw_networkx(call_graph, pos=pos) plt.gcf().set_size_inches(size) plt.show()
Example #15
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_smoke_string(self): G = self.Gs vpos = nx.random_layout(G) vpos = nx.circular_layout(G) vpos = nx.spring_layout(G) vpos = nx.fruchterman_reingold_layout(G) vpos = nx.spectral_layout(G) vpos = nx.shell_layout(G) if self.scipy is not None: vpos = nx.kamada_kawai_layout(G)
Example #16
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_scale_and_center_arg(self): sc = self.check_scale_and_center c = (4, 5) G = nx.complete_graph(9) G.add_node(9) sc(nx.random_layout(G, center=c), scale=0.5, center=(4.5, 5.5)) # rest can have 2*scale length: [-scale, scale] sc(nx.spring_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.spectral_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.circular_layout(G, scale=2, center=c), scale=2, center=c) sc(nx.shell_layout(G, scale=2, center=c), scale=2, center=c) if self.scipy is not None: sc(nx.kamada_kawai_layout(G, scale=2, center=c), scale=2, center=c)
Example #17
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_default_scale_and_center(self): sc = self.check_scale_and_center c = (0, 0) G = nx.complete_graph(9) G.add_node(9) sc(nx.random_layout(G), scale=0.5, center=(0.5, 0.5)) sc(nx.spring_layout(G), scale=1, center=c) sc(nx.spectral_layout(G), scale=1, center=c) sc(nx.circular_layout(G), scale=1, center=c) sc(nx.shell_layout(G), scale=1, center=c) if self.scipy is not None: sc(nx.kamada_kawai_layout(G), scale=1, center=c)
Example #18
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_fixed_node_fruchterman_reingold(self): # Dense version (numpy based) pos = nx.circular_layout(self.Gi) npos = nx.fruchterman_reingold_layout(self.Gi, pos=pos, fixed=[(0, 0)]) assert_equal(tuple(pos[(0, 0)]), tuple(npos[(0, 0)])) # Sparse version (scipy based) pos = nx.circular_layout(self.bigG) npos = nx.fruchterman_reingold_layout(self.bigG, pos=pos, fixed=[(0, 0)]) for axis in range(2): assert_almost_equal(pos[(0, 0)][axis], npos[(0, 0)][axis])
Example #19
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_center_parameter(self): G = nx.path_graph(1) vpos = nx.random_layout(G, center=(1, 1)) vpos = nx.circular_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.spring_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.fruchterman_reingold_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.spectral_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1)) vpos = nx.shell_layout(G, center=(1, 1)) assert_equal(tuple(vpos[0]), (1, 1))
Example #20
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_center_wrong_dimensions(self): G = nx.path_graph(1) assert_raises(ValueError, nx.random_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.circular_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.spring_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.fruchterman_reingold_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.fruchterman_reingold_layout, G, dim=3, center=(1, 1)) assert_raises(ValueError, nx.spectral_layout, G, center=(1, 1, 1)) assert_raises(ValueError, nx.spectral_layout, G, dim=3, center=(1, 1)) assert_raises(ValueError, nx.shell_layout, G, center=(1, 1, 1))
Example #21
Source File: test_layout.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def test_empty_graph(self): G = nx.empty_graph() vpos = nx.random_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.circular_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.spring_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.fruchterman_reingold_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.spectral_layout(G, center=(1, 1)) assert_equal(vpos, {}) vpos = nx.shell_layout(G, center=(1, 1)) assert_equal(vpos, {})
Example #22
Source File: test_layout.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def test_scale_and_center_arg(self): G = nx.complete_graph(9) G.add_node(9) vpos = nx.random_layout(G, scale=2, center=(4,5)) self.check_scale_and_center(vpos, scale=2, center=(4,5)) vpos = nx.spring_layout(G, scale=2, center=(4,5)) self.check_scale_and_center(vpos, scale=2, center=(4,5)) vpos = nx.spectral_layout(G, scale=2, center=(4,5)) self.check_scale_and_center(vpos, scale=2, center=(4,5)) # circular can have twice as big length vpos = nx.circular_layout(G, scale=2, center=(4,5)) self.check_scale_and_center(vpos, scale=2*2, center=(4,5)) vpos = nx.shell_layout(G, scale=2, center=(4,5)) self.check_scale_and_center(vpos, scale=2*2, center=(4,5)) # check default center and scale vpos = nx.random_layout(G) self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5)) vpos = nx.spring_layout(G) self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5)) vpos = nx.spectral_layout(G) self.check_scale_and_center(vpos, scale=1, center=(0.5,0.5)) vpos = nx.circular_layout(G) self.check_scale_and_center(vpos, scale=2, center=(0,0)) vpos = nx.shell_layout(G) self.check_scale_and_center(vpos, scale=2, center=(0,0))
Example #23
Source File: graph.py From nelpy with MIT License | 5 votes |
def draw_transmat_graph(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 labels = {} labels[0] = '1' labels[1]= '2' labels[2]= '3' labels[num_states-1] = str(num_states) npos=circular_layout(G, scale=1, direction='CW') lpos=circular_layout(G, scale=1.15, direction='CW') nx.draw_networkx_edges(G, npos, alpha=0.8, width=edgewidth*lw, edge_color=ec) nx.draw_networkx_nodes(G, npos, node_size=node_size, node_color='k',alpha=0.8) ax = plt.gca() nx.draw_networkx_labels(G, lpos, labels, fontsize=18, ax=ax); # fontsize does not seem to work :/ ax.set_aspect('equal') return ax
Example #24
Source File: graph.py From nelpy with MIT License | 5 votes |
def double_circular_layout(Gi, scale=1, center=None, dim=2, direction='CCW'): inner=circular_layout(Gi, center=center, dim=dim, scale=scale, direction=direction) outer=circular_layout(Gi, center=center, dim=dim, scale=scale*1.3, direction=direction) num_states = Gi.number_of_nodes() npos = {} for k in outer.keys(): npos[k+num_states] = outer[k] npos.update(inner) return npos
Example #25
Source File: visualise_graph.py From IDTxl with GNU General Public License v3.0 | 5 votes |
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'
Example #26
Source File: testgraphelement.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): N = 8 self.nodes = circular_layout(np.arange(N)) self.source = np.arange(N, dtype=np.int32) self.target = np.zeros(N, dtype=np.int32) self.edge_info = np.arange(N) self.graph = Graph(((self.source, self.target),))
Example #27
Source File: testgraphelement.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_from_networkx_with_node_attrs(self): import networkx as nx G = nx.karate_club_graph() graph = Graph.from_networkx(G, nx.circular_layout) clubs = np.array([ 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Officer', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Mr. Hi', 'Officer', 'Officer', 'Mr. Hi', 'Mr. Hi', 'Officer', 'Mr. Hi', 'Officer', 'Mr. Hi', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer', 'Officer']) self.assertEqual(graph.nodes.dimension_values('club'), clubs)
Example #28
Source File: testgraphelement.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_from_networkx_with_invalid_node_attrs(self): import networkx as nx FG = nx.Graph() FG.add_node(1, test=[]) FG.add_node(2, test=[]) FG.add_edge(1, 2) graph = Graph.from_networkx(FG, nx.circular_layout) self.assertEqual(graph.nodes.vdims, []) self.assertEqual(graph.nodes.dimension_values(2), np.array([1, 2])) self.assertEqual(graph.array(), np.array([(1, 2)]))
Example #29
Source File: testgraphelement.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_from_networkx_with_edge_attrs(self): import networkx as nx FG = nx.Graph() FG.add_weighted_edges_from([(1,2,0.125), (1,3,0.75), (2,4,1.2), (3,4,0.375)]) graph = Graph.from_networkx(FG, nx.circular_layout) self.assertEqual(graph.dimension_values('weight'), np.array([0.125, 0.75, 1.2, 0.375]))
Example #30
Source File: testgraphelement.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_from_networkx_with_invalid_edge_attrs(self): import networkx as nx FG = nx.Graph() FG.add_weighted_edges_from([(1,2,[]), (1,3,[]), (2,4,[]), (3,4,[])]) graph = Graph.from_networkx(FG, nx.circular_layout) self.assertEqual(graph.vdims, [])