自学内容网 自学内容网

python:绘制一元四次函数的曲线

编写  test_x4_x2_4x.py  如下

# -*- coding: utf-8 -*-
""" 绘制函数 y = x^4+x^2+4x-3 在 -2<=x<=2 的曲线 """
import numpy as np
from matplotlib import pyplot as plt

# 用于正常显示中文标题,负号
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

x = np.arange(-2., 2., 0.01)
y = np.power(x,4) +x**2 +4*x -3

# 可视化
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y) # 画曲线
#axes.axis('scaled') # 用缩尺制图
axes.axis('equal')
plt.title('函数 y = x^4+x^2+4x-3 的曲线')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()

运行 python test_x4_x2_4x.py 


原文地址:https://blog.csdn.net/belldeep/article/details/140412163

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!