【发布时间】:2017-03-24 21:21:59
【问题描述】:
我不知道我的脚本哪里出了问题。我打开了三个文件,它绘制了三个文件,但图形之间有一些连接线。在我看来,有连续的路线。谁能帮帮我?
inputs = (args.input).split(',')
x, y = [],[]
title = "RMSD"
xlabel = "Time (ns)"
ylabel = "RMSD (nm)"
for input in inputs:
with open(input) as f:
for line in f:
cols = line.split()
if cols[0][0] == "#":
pass
elif cols[0][0] == "@":
pass
else:
try:
if len(cols) == 2:
x.append(float(cols[0]))
y.append(float(cols[1]))
except ValueError:
pass
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x,y ,'r--', label='%s'%input)
legend = ax1.legend(loc='best', shadow=True)
ax1.set_title(title)
ax1.set_xlabel(xlabel)
ax1.set_ylabel(ylabel)
plt.savefig('data.png', dpi=500)
【问题讨论】:
-
所有点都在一个数组中。绘制点时,它们将全部连接。 (matplotlib 应该如何知道在哪一点不连接它们?)最系统的方法是每个文件有一对 x.y 数组并为每个文件发出一个绘图命令。
-
尊敬的先生,问题是,我不知道该怎么做。
标签: python-3.x csv matplotlib