-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot.py
More file actions
62 lines (55 loc) · 1.85 KB
/
plot.py
File metadata and controls
62 lines (55 loc) · 1.85 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import networkx as nx
import matplotlib.pyplot as plt
import torch
def plotfig(recorder, args):
recorder = torch.load('./saves/recorder.pt',
map_location=torch.device('cpu'))
plt.style.use('seaborn')
d = recorder['test_acc']['clients']
# mpl.rcParams['lines.linewidth'] = 2
# mpl.rcParams['lines.color'] = 'r'
plt.plot(recorder['test_acc']['server'], label='server')
for k in range(len(d)):
plt.plot(d[k], label='client{}'.format(k))
plt.legend()
plt.title('test_acc with {}'.format(args.split_method))
plt.savefig('./saves/test_acc.pdf')
def visualize(g):
nx_G = g.to_networkx()
labels = g.ndata['label']
pos = nx.spring_layout(nx_G)
# plt.figure(figsize=(8, 8))
# plt.axis('off')
nx.draw_networkx(nx_G, pos=pos, node_size=5, cmap=plt.get_cmap('coolwarm'),
node_color=labels, edge_color='k',
arrows=False, width=0.5, style='dotted', with_labels=False)
# plt.savefig('./graph.pdf')
def plotg(g):
nx_G = g.to_networkx()
# labels = g.ndata['label']
# pos = nx.spring_layout(nx_G)
# plt.figure(figsize=(8, 8))
# plt.axis('off')
nx.draw_networkx(nx_G, node_size=5, cmap=plt.get_cmap('coolwarm'),
edge_color='k',
arrows=False, width=0.5, style='dotted', with_labels=False)
plt.savefig('./graph.pdf')
def subfigs(graphs, args):
plt.subplot(221)
# visualize(graphs[0])
plotg(graphs[0])
plt.title('client1')
plt.subplot(222)
# visualize(graphs[1])
plotg(graphs[1])
plt.title('client2')
plt.subplot(223)
# visualize(graphs[2])
plotg(graphs[2])
plt.title('client3')
plt.subplot(224)
# visualize(graphs[3])
plotg(graphs[3])
plt.title('client0')
plt.suptitle(args.split_method)
plt.savefig('./allgraphs.pdf')