我用python编写了一个相对简单的函数,可以用来绘制一个数据集的时域历史以及一个数据集在快速傅立叶变换后的频域响应。在这个函数中,我使用命令from pylab import *引入所有必要的功能。然而,尽管成功地创建了这个情节,我还是得到了一个警告import * only allowed at the module level.
因此,如果使用命令from pylab import *不是首选方法,那么如何正确地从pylab加载所有必需的功能。代码附在下面。另外,在函数退出后,是否有方法关闭图,我尝试了子块无法识别的plt.close()?def Time_Domain_Plot(Directory,Title,X_Label,Y_Label,X_Data,Y_Data):
# Directory: The path length to the directory where the output file is
# to be stored
# Title: The name of the output plot, which should end with .eps or .png
# X_Label: The X axis label
# Y_Label: The Y axis label
# X_Data: X axis data points (usually time at which Yaxis data was acquired
# Y_Data: Y axis data points, usually amplitude
from pylab import *
from matplotlib import rcParams
rcParams.update({'figure.autolayout': True})
Output_Location = Directory.rstrip() + Title.rstrip()
fig,plt = plt.subplots()
matplotlib.rc('xtick',labelsize=18)
matplotlib.rc('ytick',labelsize=18)
plt.set_xlabel(X_Label,fontsize=18)
plt.set_ylabel(Y_Label,fontsize=18)
plt.plot(X_Data,Y_Data,color='red')
fig.savefig(Output_Location)
plt.clear()