import matplotlib.pyplot as plt
x=[]
y=[]
for i in range(1,11):
x.append(i)
y.append(2*i+10)
plt.plot(x,y,"-*")
plt.grid()
plt.axis([-2,16,10,38])
plt.xlabel("children")
plt.ylabel("apples")
plt.show()
也可以寫成
import matplotlib.pyplot as plt
x=[x for x in range(0,10)]
y=[(2*y+10) for y in x]
plt.plot(x,y,"-*")
plt.grid()
plt.xlabel("Xchildren")
plt.ylabel("Yapples")
plt.show()
#y=f(x)=5x+1000 x從1到1000 分成10等份
import matplotlib.pyplot as plt
import numpy as np
x=np.linspace(1,1000,10) #x從1到1000 分成10等份
#print(type(x))
y=5*x+1000
plt.plot(x,y,"-*")
plt.grid()
plt.axis([0,1000,1000,6000])
plt.xlabel("number")
plt.xlabel("money")
plt.show()
沒有留言:
張貼留言