Python 使用1个打印功能打印多个csv文件

Python 使用1个打印功能打印多个csv文件,python,matplotlib,plot,data-science,spyder,Python,Matplotlib,Plot,Data Science,Spyder,我有4个不同的csv文件(从1个xlsm工作簿中提取)。我的plot函数有点复杂,但在这些文件中的每一个上都非常完美。如果我尝试用循环绘制所有4个文件,我总是得到一个 ValueError:数组的长度必须相同 然后,函数将绘制列表中的第一个元素。我想为csv列表中的每个文件绘制相同的plt.figure和子图。我认为脚本试图在一个绘图上绘制所有不同的csv文件(csv文件具有相同的结构,但行数不同) 如果不设置子地块,它们将在同一个地块上绘制。有不止一种方法可以做到这一点,但我通常使用的是fig

我有4个不同的
csv
文件(从1个xlsm工作簿中提取)。我的plot函数有点复杂,但在这些文件中的每一个上都非常完美。如果我尝试用循环绘制所有4个文件,我总是得到一个

ValueError:数组的长度必须相同

然后,函数将绘制列表中的第一个元素。我想为csv列表中的每个文件绘制相同的plt.figure和子图。我认为脚本试图在一个绘图上绘制所有不同的csv文件(csv文件具有相同的结构,但行数不同)


如果不设置子地块,它们将在同一个地块上绘制。有不止一种方法可以做到这一点,但我通常使用的是fig,axis_阵列

import matplotlib.pyplot as plt

def plotMSN(i):
    #whatever you're doing in here
    ax.plot() #plot it on its own axis, this will reference the one you're on in your loop


fig, axis_array = plt.subplots(len(csvlist), 1, subplot_kw = {'aspect':1}) #this will set up subplots that are arranged vertically
for i, ax in zip(csvlist, axis_array):
    plotMSN(i)
预计到达时间:

OP显然想绘制每个文件并使用该函数。为此,OP需要修改:

def plotMSN(i):
  #determine an appropriate name either in this function or in the loop that calls it 
  #plotting stuff here
  fig.savefig(new_filename)
  plt.close() # this prevents it from using the same instance over and over. 

我的绘图函数非常大,现在很难全部重写。我能不能把这个绘图函数放在一个额外的脚本文件中,并在每个循环的不同csv文件上调用它?我不需要以子图的形式绘制,只需要以pdf文件的形式绘制。如果希望每个文件有一个打印文件,请将其保存在函数中,然后plt.close()。
def plotMSN(i):
  #determine an appropriate name either in this function or in the loop that calls it 
  #plotting stuff here
  fig.savefig(new_filename)
  plt.close() # this prevents it from using the same instance over and over.