python画抛物线_如何使用python的matplotlib模块画抛物线

1

第一步,点击键盘 win+r,打开运行窗口;在窗口中输入“cmd",点击确定,打开windows命令行窗口。

python画抛物线_如何使用python的matplotlib模块画抛物线_第1张图片

python画抛物线_如何使用python的matplotlib模块画抛物线_第2张图片

python画抛物线_如何使用python的matplotlib模块画抛物线_第3张图片

2

第二步,在cmd命令行窗口中输入"python",进入python交互窗口。

python画抛物线_如何使用python的matplotlib模块画抛物线_第4张图片

3

第三步,引入matplotlib模块的pyplot()函数,并重命名为plt;引入numpy模块,并重命名为np.

python画抛物线_如何使用python的matplotlib模块画抛物线_第5张图片

4

第四步,绘制抛物线y^2=4*x,需要将此方程转换成两个函数:y=(4*x)^0.5、y=-1*(4*x)^0.5。使用函数np.arrange(0,4,0.001)创建变量x1的取值范围,是一个一维数组,使用y1=np.sqrt(4*x1),创建y1是与自变量x1相对应的一维数组。同样的方法,创建x2和y2的数组。

python画抛物线_如何使用python的matplotlib模块画抛物线_第6张图片

5

第五步,使用函数plt.plot(x1,y1,x2,y2)绘制函数:y=(4*x)^0.5、y=-1*(4*x)^0.5^0.5的图像。

python画抛物线_如何使用python的matplotlib模块画抛物线_第7张图片

6

第六步,使用函数plt.title()给图像添加标题,使用函数plt.xlabel()给横轴添加标签,使用函数plt.ylabel()给纵轴添加标签,使用函数plt.tick_params()设置刻度标记的大小。

python画抛物线_如何使用python的matplotlib模块画抛物线_第8张图片

7

第七步,使用函数plt.show()显示抛物线的图像。

python画抛物线_如何使用python的matplotlib模块画抛物线_第9张图片

python画抛物线_如何使用python的matplotlib模块画抛物线_第10张图片

END

你可能感兴趣的:(python画抛物线)