绘制两个系列数据



我是pythion的新手,我想简单地知道如何使用绘图函数在图中绘制以下代码产生的一系列数据?

我希望x轴成为some_function的结果,而y轴是t1的结果。

这是用于任务,我只能使用情节,而不是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))

不确定您是否想要散点图或线图,因此我包括了两个选项。

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')

最新更新