More than 20 figures have been opened.
plt.cla() plt.close("all")
示例代码
dynamicDistribution = np.ones((frames, 512, 512, 4)) dynamicDistributionDataPath = r'D:\PythonProject\QTNLS\resources\dynamicDistribution.npy' if os.path.exists(dynamicDistributionDataPath): dynamicDistribution = np.load(dynamicDistributionDataPath) else: for t in range(frames): print(t) G = nx.Graph() for i in range(numNeurons): for j in range(i, numNeurons): if dynamicMI[t,i,j] > thres: G.add_edge(i,j) # print(G.degree()) degree_sequence = sorted([d for n, d in G.degree()], reverse=True) fig, ax = plt.subplots(figsize=(4, 4), dpi=128) ax.bar(*np.unique(degree_sequence, return_counts=True)) ax.set_xlim(xmin = 0, xmax = numNeurons)#度分布,最大的度就是所有人都连上了 ax.set_ylim(ymin = 0, ymax = 15)#度分布,最大的度就是所有人都连上了 ax.set_title("Degree histogram") ax.set_xlabel("Degree") ax.set_ylabel("# of Nodes") buf = io.BytesIO() fig.savefig(buf, format='raw', dpi=128) buf.seek(0) img_arr = np.frombuffer(buf.getvalue(), dtype=np.uint8) buf.close() plt.cla() plt.close("all") w, h = fig.canvas.get_width_height() im = img_arr.reshape((int(h), int(w), -1)) im = im.transpose((1, 0, 2)) dynamicDistribution[t,:,:,:] = im np.save(dynamicDistributionDataPath,dynamicDistribution)