I'm trying to save the networkx graph I'm making in python to a png file, but plt.savefig only saves a blank white png. Here's the execution line:
modeling.makeGraph(G, people)
plt.figure(3,figsize=(12,12))
modeling.draw(G, people)
plt.show()
plt.savefig("ContactTrace.png")
Here's the draw function:
def redNodes(graph, people):
redList = []
for node in list(graph.nodes):
if people[node].testedPositive:
redList.append(node)
return redList
def blueNodes(graph, people):
blueList = []
for node in list(graph.nodes):
if not people[node].testedPositive:
blueList.append(node)
return blueList
def draw(graph, people):
pos = nx.spring_layout(graph)
nx.draw_networkx_nodes(graph, pos, nodelist = redNodes(graph, people), with_labels = True, node_color = "r")
nx.draw_networkx_nodes(graph, pos, nodelist = blueNodes(graph, people), with_labels = True)
nx.draw_networkx_edges(graph, pos, width = 2)
setLabels(graph, people, pos)
def setLabels(graph, people, pos):
labels = {}
nodes = list(graph.nodes)
for i in range(len(nodes)):
labels[nodes[i]] = nodes[i] + "\n" + people[nodes[i]].lastName + ",\n" + people[nodes[i]].firstName
nx.draw_networkx_labels(graph,pos, labels,font_size = 10.5, font_weight = "bold")
return