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

编写 test_x3_3x.py  如下

# -*- coding: utf-8 -*-
""" 绘制函数 y = x^3+3x+4 在 -3<=x<=3 的曲线 """
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(-3., 3., 0.01)
y = np.power(x,3) -3.0*x +4

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

运行 python test_x3_3x.py 


编写  test_x3_3x2_3x.py  如下

# -*- coding: utf-8 -*-
""" 绘制函数 y = x^3-3x^2+3x+1 在 -1<=x<=1 的曲线 """
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(-1., 1., 0.01)
y = np.power(x,3) -3.0*np.power(x,2) +3.0*x +1

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

运行 python test_x3_3x2_3x.py 

相关推荐

  1. OPenCV中绘制多条多边形曲线函数polylines使用

    2024-07-15 09:52:01       34 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-15 09:52:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-15 09:52:01       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-15 09:52:01       58 阅读
  4. Python语言-面向对象

    2024-07-15 09:52:01       69 阅读

热门阅读

  1. 对AAC解码的理解

    2024-07-15 09:52:01       22 阅读
  2. 【Karapathy大神build-nanogpt】Take Away Notes

    2024-07-15 09:52:01       24 阅读
  3. C的分文件编写与动态库

    2024-07-15 09:52:01       26 阅读
  4. Spring Boot中的安全配置与实现

    2024-07-15 09:52:01       20 阅读
  5. 设计模式--抽象工厂模式

    2024-07-15 09:52:01       23 阅读
  6. 【C++ 】类与对象 -- 纯虚函数与抽象类

    2024-07-15 09:52:01       22 阅读