Python 3.x 来自不同输入文件的一个fig中的多个图形

Python 3.x 来自不同输入文件的一个fig中的多个图形,python-3.x,csv,matplotlib,Python 3.x,Csv,Matplotlib,我不知道我的剧本哪里出了问题。我打开了三个文件,它画了三个文件,但在图中有一些连接线。在我看来,这条线是连续的。有人能帮我吗 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 =

我不知道我的剧本哪里出了问题。我打开了三个文件,它画了三个文件,但在图中有一些连接线。在我看来,这条线是连续的。有人能帮我吗

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)
运行我的脚本后的图像:

一个选项是在循环中绘制图形,每个输入文件一个绘图命令

inputs = (args.input).split(',')

x, y = [],[]
title = "RMSD"
xlabel = "Time (ns)"
ylabel = "RMSD (nm)"

fig = plt.figure()
ax1 = fig.add_subplot(111)

for inp in inputs:
    x, y = [],[]
    with open(inp) as f:
        for line in f:
            cols = line.split()
            if cols[0][0] not in ["#","@"]:
                try:
                    if len(cols) == 2:
                        x.append(float(cols[0]))
                        y.append(float(cols[1]))
                except ValueError:
                      pass
    ax1.plot(x,y ,'r--', label='%s'%inp)



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数组对,每个文件发出一个绘图命令。亲爱的先生,问题是,我不知道怎么做。