简体   繁体   English

名称“情节”未定义

[英]name 'plot' is not defined

I installed succesfully scitools_no_easyviz from conda (I work on Spyder), but I cannot import plot. 我从conda成功安装了scitools_no_easyviz(我在Spyder上工作),但是无法导入绘图。 To be more specific, here's my code 更具体地说,这是我的代码

from scitools.std import *

def f(t):
    return t**2*exp(-t**2)

t = linspace(0, 3, 51)
y = f(t)
plot(t, y)

savefig('tmp1.pdf') # produce PDF
savefig('tmp1.png') # produce PNG

figure()

def f(t):
    return t**2*exp(-t**2)

t = linspace(0, 3, 51)
y = f(t)
plot(t, y)
xlabel('t')
ylabel('y')
legend('t^2*exp(-t^2)')
axis([0, 3, -0.05, 0.6])   # [tmin, tmax, ymin, ymax]
title('My First Easyviz Demo')

figure()
plot(t, y)
xlabel('sss')

When I run the code, I get the following error 运行代码时,出现以下错误

NameError: name 'plot' is not defined NameError:未定义名称“图”

What could be the problem? 可能是什么问题呢?

Using import * is not considered a best practice, although very practical. 尽管很实用,但是使用import *并不是最佳实践。 Try importing the functions you need, such as: 尝试导入所需的功能,例如:

from scitools.std import plot

Additionally, this way you will know if "plot" is valid when you import it along side any other function. 另外,通过这种方式,当您将“ plot”与其他函数一起导入时,您将知道它是否有效。

Ensure you have the dependencies installed in order to use the package as noted here at https://code.google.com/archive/p/scitools/wikis/Installation.wiki 确保安装了依赖项,以便使用https://code.google.com/archive/p/scitools/wikis/Installation.wiki 此处所述的软件包。

Additionally, installed following these instruction latest package and your code runs perfectly well with it. 此外,按照以下说明安装最新软件包 ,您的代码可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM