----------七夕就要來了,不論你是不是一個人,都祝你開心快樂啊-------------
代碼:
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 解決中文亂碼
"""
* @Author: xiaofang
學習中遇到問題沒人解答?小編創建了一個Python學習交流QQ群:732481539
尋找有志同道合的小伙伴,互幫互助,群裡還有不錯的視頻學習教程和PDF電子書!
"""
fig = plt.figure(figsize=(8, 8))
ax = fig.gca(projection='3d')
[x, t] = np.meshgrid(np.array(range(25)) / 24.0, np.arange(0, 575.5, 0.5) / 575 * 30 * np.pi - 4 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
change = np.sin(20 * t) / 50
u = 1 - (1 - np.mod(3.3 * t, 2 * np.pi) / np.pi) ** 4 / 2 + change
y = 2 * (x ** 2 - x) ** 2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p)) * 1.5
h = u * (x * np.cos(p) - y * np.sin(p))
c = plt.get_cmap('magma')
surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1,
cmap=c, linewidth=0, antialiased=True)
ax.set_xticks([])
ax.set_yticks([])
ax.set_zticks([])
plt.rc('font', family='SimHei', size=11)
plt.title('永生花送給我的永恆摯愛')
plt.show()
效果: