七夕就要來了,不論你是不是一個人,都祝你開心快樂啊
代碼:
from matplotlib import pyplot as plt
import matplotlib.animation as animation
import numpy as np
t = np.linspace(0, 6, 100)
x = 16 * np.sin(t) ** 3
y = 13 * np.cos(t) - 5 * np.cos(2 * t) - 2 * np.cos(3 * t) - np.cos(4 * t)
data = [i for i in zip(x, y)]
"""
* @Author: xiaofang
學習中遇到問題沒人解答?小編創建了一個Python學習交流QQ群:732481539
尋找有志同道合的小伙伴,互幫互助,群裡還有不錯的視頻學習教程和PDF電子書!
"""
def plot_love(data):
x, y = data
plt.scatter(x, y, 60, c="r", alpha=0.7, marker=r"$\heartsuit$")
fig = plt.figure(figsize=(5, 3), dpi=100)
plt.axis("off")
animator = animation.FuncAnimation(fig, plot_love, frames=data, interval=80)
animator.save("love.gif", writer='pillow')
效果: