Skip to content

Commit 904dd3d

Browse files
committed
Add more tests
1 parent 29fd66f commit 904dd3d

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test12.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import networkx as nx
2+
import matplotlib.pyplot as plt
3+
import numpy as np
4+
5+
# Create a random graph with 10,000 nodes and 50,000 edges
6+
G = nx.gnm_random_graph(1000, 5000)
7+
8+
# Set random weights for the edges
9+
weights = np.random.rand(len(G.edges))
10+
nx.set_edge_attributes(G, dict(zip(G.edges, weights)), 'weight')
11+
12+
# Generate a layout using the spring layout algorithm
13+
pos = nx.spring_layout(G)
14+
15+
# Assign colors to the nodes based on their degree
16+
node_colors = np.array(list(dict(G.degree()).values()))
17+
node_colors = (node_colors - node_colors.min()) / (node_colors.max() - node_colors.min())
18+
19+
# Assign colors to the edges based on their weight
20+
edge_weights = nx.get_edge_attributes(G, 'weight')
21+
edge_weights_norm = (np.array(list(edge_weights.values())) - min(edge_weights.values())) / (max(edge_weights.values()) - min(edge_weights.values()))
22+
cmap = plt.cm.get_cmap('Blues')
23+
edge_colors = cmap(edge_weights_norm)
24+
25+
# Draw the graph using the layout and color scheme
26+
nx.draw(G, pos=pos, node_color=node_colors, edge_color=edge_colors, with_labels=False, node_size=5, width=0.5)
27+
28+
# Add a title and subtitle to the plot
29+
plt.title("Random Graph with 10,000 Nodes and 50,000 Edges")
30+
plt.suptitle("Generated using the gnm_random_graph() function from NetworkX")
31+
32+
# Display the plot
33+
plt.show()

test13.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import networkx as nx
2+
import matplotlib.pyplot as plt
3+
4+
# Create a random graph with 50 nodes
5+
G = nx.fast_gnp_random_graph(50, 0.2)
6+
7+
# Generate a layout using the spring layout algorithm
8+
pos = nx.spring_layout(G)
9+
10+
# Draw the graph using the layout and default settings
11+
nx.draw(G, pos)
12+
13+
# Add a title to the plot
14+
plt.suptitle("Generated using the fast_gnp_random_graph() function from NetworkX", fontsize=12)
15+
16+
# Display the plot
17+
plt.show()

0 commit comments

Comments
 (0)