Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 循环打印,仅获取最后一个打印_Python_Matplotlib_Plot - Fatal编程技术网

Python 循环打印,仅获取最后一个打印

Python 循环打印,仅获取最后一个打印,python,matplotlib,plot,Python,Matplotlib,Plot,我正在使用matplotlib。代码: for new_counter in range(counter+1): print new_counter Qbers = final_data[(final_data["Dataset"]==counter) & (final_data["Qber"] > 0) ] x1 = Qbers.index.tolist() y1 = Qbers["Qber"].tolist() Raws = final_

我正在使用matplotlib。代码:

for new_counter in range(counter+1):
    print new_counter
    Qbers = final_data[(final_data["Dataset"]==counter) & (final_data["Qber"] > 0) ]
    x1 = Qbers.index.tolist()
    y1 = Qbers["Qber"].tolist()
    Raws = final_data[(final_data["Dataset"]==counter) & (final_data["Raw key"] > 0) ]
    x2 = Raws.index.tolist()
    y2 = Raws["Raw key"].tolist()
    # Two subplots, the axes array is 1-d http://matplotlib.org/examples/pylab_examples/subplots_demo.html
    f, axarr = plt.subplots(2, sharex=True)
    axarr[0].grid()
    axarr[0].plot(x1, y1)
    axarr[0].set_title('Sharing X axis')
    axarr[1].grid()
    axarr[1].plot(x2, y2)
    plt.savefig(str(counter)+'foo.eps')
    plt.clf()

我只收到最后一个绘图的文件,根据我的数据,我应该收到其中的6个。如何解决这个问题?附加问题:如何防止创建带有绘图的交互式窗口?

看起来您没有生成唯一的文件名。您可能想要:

plt.savefig(str(new_counter)+'foo.eps')

这里有一个相关的问题: