输入3次并生成3个图形功能
首先,感谢您的帮助。 正如我在标题上所说的,我想进行3次输入并生成3个图表功能
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
times = range(1, 1)
for i in times:
def my_func2(x):
a=int(input())
return x**a
x=np.linspace(0,2)
y=my_func2(x)
plt.plot(x, y)
plt.xlabel("x",size=14)
plt.ylabel("y",size=14)
plt.grid()
plt.show()
i=i+1
First of all Thanks for your help.
As I said at title, I want to make input 3 times and generate 3 graphs function
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
times = range(1, 1)
for i in times:
def my_func2(x):
a=int(input())
return x**a
x=np.linspace(0,2)
y=my_func2(x)
plt.plot(x, y)
plt.xlabel("x",size=14)
plt.ylabel("y",size=14)
plt.grid()
plt.show()
i=i+1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的凹痕错误 - 这改变了Python中的一切。您尝试在
my_func2()
内绘制y = y = my_func2(x)
内部 def my_func2(x): - 因此您永远不会运行此功能。如果要重复3次,请使用
range(3)
而不是range(1,1)
且没有i = i = i + 1
但是我会没有功能
You have wrong indentations - and this change everything in Python. You try to plot inside
my_func2()
and you runy=my_func2(x)
insidedef my_func2(x):
- so you never run this function.And if you want to repeat 3 times then use
range(3)
instead ofrange(1, 1)
and withouti = i + 1
But I would do it without function