python中的pylab_在Python2.7中,在函数级导入pylab的首选方法是什么?

我用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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值