matplotlib 绘制动态函数图例程
以下程序主要实现两个功能
- 在同一个图像里面绘制多条曲线
- 画面上让曲线动态的平移
import numpy as np
import matplotlib.pyplot as plt
num_points = 1000
k = 60
x = np.linspace(-10, 5, num_points)
y2 = np.zeros(num_points)
pic = plt.subplot()
for k in range(-6, 60, 2):
y = -x ** 3 - 6 * x ** 2 + 11 * x + 6 + k
pic.plot(x, y, label='func')
pic.plot(x, y2, label='x=0')
pic.plot(y2, np.linspace(y[0], y[-1], num_points), label='y=0')
pic.set_xlabel('x axis')
pic.set_ylabel('y axis')
pic.set_title('Function')
plt.xlim([-10.2,5])
plt.ylim([-210,330])
pic.legend()
plt.pause(0.05)
pic.clear()
plt.show()