python动态描绘洛伦兹吸引子图像

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

xs, ys, zs = [], [], []


def lorenz_attractor():
    mpl.rcParams["legend.fontsize"] = 10
    fig = plt.figure()
    ax = Axes3D(fig)
    plt.ion()
    a, b, c = 10.0, 28.0, 8.0 / 3.0         # a为普兰特数,b为规范化的瑞利数,c与几何形状相关
    h = 0.01                                # 微分迭代步长
    x0, y0, z0 = 0.1, 0, 0
    for i in range(10000):
        x1 = x0 + h * a * (y0 - x0)
        y1 = y0 + h * (x0 * (b - z0) - y0)
        z1 = z0 + h * (x0 * y0 - c * z0)
        x0, y0, z0 = x1, y1, z1
        xs.append(x0)
        ys.append(y0)
        zs.append(z0)
        plt.cla()
        ax.set_xlabel('X')
        ax.set_xlim(-35, 35)
        ax.set_ylabel('Y')
        ax.set_ylim(-35, 35)
        ax.set_zlabel('Z')
        ax.set_zlim(-1, 50)
        ax.plot(xs, ys, zs, label="Lorenz's strange attractor")
        ax.legend()
        plt.pause(0.001)


if __name__ == "__main__":
    lorenz_attractor()
    pass

 

你可能感兴趣的:(混沌Chaos)