-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from tiwavaldese/main
Creating a python script #5
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
https://github.com/networkx/outreachy/pull/251 | ||
|
||
https://github.com/networkx/outreachy/pull/257 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
|
||
#Create a DiGraph graph object | ||
G = nx.DiGraph() | ||
|
||
#Add multiple nodes of different types | ||
G.add_node(1) | ||
G.add_nodes_from([2,3]) | ||
G.add_node(4) | ||
G.add_node(5) | ||
G.add_node(6) | ||
G.add_nodes_from("spam") | ||
|
||
#Add multiple edges between nodes | ||
G.add_edge(1,(2,3)) | ||
G.add_edge((2,3),1) | ||
G.add_edge(1,3) | ||
G.add_edge(3,1) | ||
G.add_edge((2,3),5) | ||
G.add_edge(5,(2,3)) | ||
G.add_edge((2,3),6) | ||
G.add_edge(6,(2,3)) | ||
G.add_edge(4,5) | ||
G.add_edge(5,4) | ||
G.add_edge(4,'s') | ||
G.add_edge('s',4) | ||
G.add_edge(5,'p') | ||
G.add_edge('p',5) | ||
G.add_edge('a',6) | ||
G.add_edge(6,'a') | ||
G.add_edge(2,'m') | ||
G.add_edge('m',2) | ||
|
||
# Find the shortest path and print | ||
st_p = nx.shortest_path(G) | ||
print(st_p) | ||
|
||
# Plot the Graph | ||
nx.draw(G, with_labels = True, node_color= 'red') | ||
plt.show() |