使用import
导入模块matplotlib.pyplot
,并简写成plt
使用import
导入模块numpy
,并简写成np
import matplotlib.pyplot as plt #imort pyplot
import numpy as np #import numpy
x=np.linspace(-1,1,50)
y=2*x+1
plt.figure() #difine a figure window
plt.plot(x,y) #plot the figure
plt.show() #show the figure
使用np.linspace
定义x:范围是(-1,1);个数是50. 仿真一维数据组(x
,y
)表示曲线1.
使用plt.figure
定义一个图像窗口. 使用plt.plot
画(x
,y
)曲线. 使用plt.show
显示图像.