我是Pythion的新手,我想简单地知道如何使用plot函数在图形中绘制以下代码产生的一系列数据?
我希望x轴是some_function的结果,y轴是t1的结果。
这是一个作业,我只能使用plot,而不是matplotlib,因为我们没有学过。
谢谢
from pylab import *
def some_function(ff, dd):
if dd >=0 and dd <=300:
tt = (22/-90)*ff+24
elif dd >=300 and dd <=1000:
st = (22/-90)*(ff)+24
gg = (st-2)/-800
tt = gg*dd+(gg*-1000+2)
else:
tt = 2.0
return tt
t1=arange(0,12000,1000)
print(t1)
for x in t1:
print(some_function(55,x))发布于 2019-05-19 15:48:58
我不确定你是想要散点图,还是折线图,所以我把这两个选项都包括进来了。
from pylab import *
import matplotlib.pyplot as plt
def some_function(ff, dd):
if dd >=0 and dd <=300:
tt = (22/-90)*ff+24
elif dd >=300 and dd <=1000:
st = (22/-90)*(ff)+24
gg = (st-2)/-800
tt = gg*dd+(gg*-1000+2)
else:
tt = 2.0
return tt
t1=arange(0,12000,1000)
x_data = [some_function(55,x) for x in t1]
y_data = t1
# Scatter plot
plt.scatter(x_data, y_data)
# Line plot
plt.plot(x_data, y_data)
plt.show()
#Optionally, you can save the figure to a file.
plt.savefig("my_plot.png")如果您确实不能直接使用matplotlib,只需运行:
# Scatter plot
scatter(x_data, y_data)
# Line plot
plot(x_data, y_data)
show()
savefig('my_plot.png')https://stackoverflow.com/questions/56205290
复制相似问题