Untitled
unknown
plain_text
a year ago
751 B
4
Indexable
import networkx as nx import matplotlib.pyplot as plt # Define the data data = [ ('a', 'b', 0.2), ('b', 'e', 0.2), ('c', 'd', 0.8), ('d', 'f', 0.6), ('e', 'f', 0.3), ('f', 'g', 1), ('g', 'h', 0.4), ('h', 'end', 0.3) ] # Create a directed graph G = nx.DiGraph() # Add nodes and edges with weights for task1, task2, time in data: G.add_edge(task1, task2, weight=time) # Plot the graph pos = nx.spring_layout(G) # positions for all nodes nx.draw(G, pos, with_labels=True, node_size=1500, node_color="skyblue", font_size=12, font_weight="bold", arrowsize=20) edge_labels = nx.get_edge_attributes(G, 'weight') nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels) plt.title("Precedence Diagram") plt.show()
Editor is loading...
Leave a Comment