Skip to content

Commit

Permalink
updated some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
benmaier committed Apr 22, 2021
1 parent ccf5fc0 commit cf6568c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions smallworld/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as pl

#def plot_edge(ax,N,u,v,phis,color=None):
colors = [
colors = [
'#666666',
'#1b9e77',
'#e7298a'
Expand Down Expand Up @@ -42,7 +42,7 @@ def is_shortrange(i,j,N,k_over_2):

return distance <= k_over_2 or N-distance <= k_over_2

def draw_network(G, k_over_2, R=10,focal_node=None, ax=None):
def draw_network(G, k_over_2, R=10,focal_node=None, ax=None,markersize=None,linewidth=1.0,linkcolor=None):
"""
Draw a small world network.
Expand Down Expand Up @@ -74,12 +74,12 @@ def draw_network(G, k_over_2, R=10,focal_node=None, ax=None):

if focal_node is None:
non_focal_alpha = 1
focal_lw = 1.0
non_focal_lw = 1.0
focal_lw = linewidth*1.0
non_focal_lw = linewidth*1.0
else:
non_focal_alpha = 0.6
focal_lw = 1.5
non_focal_lw = 1.0
focal_lw = linewidth*1.5
non_focal_lw = linewidth*1.0


N = G_.number_of_nodes()
Expand All @@ -94,7 +94,9 @@ def draw_network(G, k_over_2, R=10,focal_node=None, ax=None):
points[:,1] = y
origin = np.zeros((2,))

col = colors
col = list(colors)
if linkcolor is not None:
col[0] = linkcolor


ax.axis('equal')
Expand Down Expand Up @@ -154,7 +156,7 @@ def draw_network(G, k_over_2, R=10,focal_node=None, ax=None):

ax.plot(these_x, these_y,c=this_color,alpha=this_alpha,lw=this_lw)

ax.plot(x,y,'o',c='k')
ax.plot(x,y,'o',c='k',mec='#ffffff',ms=markersize)

return ax

Expand Down
4 changes: 2 additions & 2 deletions smallworld/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def assert_parameters(N,k_over_2,beta):
def get_largest_component(G):
"""Return the largest connected component of graph `G`."""

subgraphs = nx.connected_component_subgraphs(G,copy=False)
new_G = max(subgraphs, key=len)
new_G = max([G.subgraph(c) for c in nx.connected_components(G)], key=len)
G = nx.convert_node_labels_to_integers(new_G)

return G
Expand Down Expand Up @@ -58,6 +57,7 @@ def get_sparse_matrix_from_rows_and_cols(N, rows, cols):
def get_random_walk_eigenvalue_gap(A,maxiter=10000):

W = A.copy()
W = W.astype(float)
degree = np.array(W.sum(axis=1),dtype=float).flatten()

for c in range(W.shape[1]):
Expand Down

0 comments on commit cf6568c

Please sign in to comment.