-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot.py
More file actions
25 lines (19 loc) · 1.04 KB
/
Copy pathplot.py
File metadata and controls
25 lines (19 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from matplotlib import pyplot as plt
import networkx as nx
import matplotlib
matplotlib.use("agg")
def maximum_cut(graph, nodes_set1, nodes_set2, cut_edges, uncut_edges, filename):
pos = nx.spring_layout(graph)
nx.draw_networkx_nodes(graph, pos, nodelist=nodes_set1, node_color='r')
nx.draw_networkx_nodes(graph, pos, nodelist=nodes_set2, node_color='c')
nx.draw_networkx_edges(graph, pos, edgelist=cut_edges, style='dashdot', alpha=0.5, width=3)
nx.draw_networkx_edges(graph, pos, edgelist=uncut_edges, style='solid', width=3)
nx.draw_networkx_labels(graph, pos)
plt.savefig(filename, bbox_inches='tight')
def graph_with_colored_node_subset(graph, node_subset, filename):
pos = nx.spring_layout(graph)
nx.draw_networkx_nodes(graph, pos, nodelist=graph.nodes, node_color='r')
nx.draw_networkx_nodes(graph, pos, nodelist=node_subset, node_color='c')
nx.draw_networkx_edges(graph, pos, edgelist=graph.edges, style='solid', width=3)
nx.draw_networkx_labels(graph, pos)
plt.savefig(filename, bbox_inches='tight')