Python写爱心闪光动图

前言

520了程序员表白不要来点code????二十行代码闪光❤送给你!

代码

from matplotlib import pyplot as plt
import numpy as np

x = np.linspace(-1.75, 1.75, 1000)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
plt.xlim(-2,2)
plt.ylim(-1.5,2.5)
plt.ion()
for i in range(1,1000):
    y = np.sin(i/10 * np.pi * (x)) * np.e / 3 * (np.pi - x ** 2) ** 0.5 + np.abs(x) ** (2/3)
    print("文章不点赞就偷走了太过分了吧!")
    lines = ax.plot(x, y)
    plt.pause(0.05)
    plt.title("i = " + str(i/10))
    ax.lines.remove(lines[0])

效果

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37668436/article/details/106235149