我正在遍历不同分子的名称列表,并尝试为每个分子生成单独的无花果。但是对于每个连续的分子,新数字也包含所有以前的数据。我在收集数据后打印了数据,并且每个循环都显示了正确的数量。这是我的完整代码
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
mols = ["P_Z1", "P_Z2", "TT_Z1", "TT_Z2", "TP_Z1", "TP_Z2"]
for mol in mols:
en = []
den = []
with open (mol+"clustered.txt") as f:
for line in f:
e = line.strip().split()[1]
en.append(e)
with open (mol+"densities.txt") as g:
for line in g:
d = line.strip()
den.append(d)
data = zip(en,den)
print data
for energy, density in data:
plt.xlabel("Density g/cubic cm")
plt.ylabel("Energy kJ/mol")
ax = plt.gca()
ax.spines["right"].set_color('none')
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('left')
ax.spines["bottom"].set_color('none')
ax.xaxis.set_label_position('top')
ax.spines['left'].set_color('black')
ax.spines['top'].set_color('black')
ax.xaxis.label.set_color('black')
ax.yaxis.label.set_color('black')
ax.tick_params(colors='black')
plt.plot(density, energy, "ro")
plt.savefig(mol+".png", bbox_inches="tight", dpi=200, transparent=True)
任何帮助将不胜感激!