21 lines
361 B
Python
21 lines
361 B
Python
import networkx as nx
|
|
import matplotlib.pyplot as plt
|
|
|
|
def main():
|
|
# Tree
|
|
G = nx.DiGraph()
|
|
G.add_node("A")
|
|
G.add_node("B")
|
|
G.add_node("C")
|
|
G.add_edge("A", "B")
|
|
G.add_edge("B", "C")
|
|
print(G.nodes())
|
|
print(G.edges())
|
|
print(G.degree())
|
|
|
|
nx.draw(G, with_labels=True)
|
|
plt.show()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|