Python networkx graph: Do not draw old graph together with new graph
问题 The below is my code: import networkx as nx for i in range(2): G = nx.DiGraph() if i==0: G.add_edge("A", "B") elif i==1: G.add_edge("A", "C") import matplotlib.pyplot as plt nx.draw(G) plt.savefig(str(i)+".png") G.clear() It should draw line AB in file 0.png and draw line AC in file 1.png. But, after I ran it. In 0.png, there is one line AB, but in 1.png, there are two lines: AB and AC. It seems that the memory for 0.png is not cleaned, although I have had "G.clear()". Does anybody know how