七夕就要來了,不論你是不是一個人,都祝你開學快樂~~~
可自定義輸入內容
代碼:
"""
* @Author: xiaofang
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.font_manager import FontProperties
fig = plt.figure(figsize=(6, 8))
ax = fig.gca(projection='3d')
elev = 22
azim = 2.5
ax.view_init(elev, azim) # 改變繪制圖像的視角,即相機的位置,azim沿著z軸旋轉,elev沿著y軸
font_set = FontProperties(fname=r"C:\Windows\Fonts\simhei.TTF", size=20)
ax.text(1, -0.8, 0, '"唯一的花送給我愛的寶貝Love"', fontproperties=font_set)
# 學習中遇到問題沒人解答?小編創建了一個Python學習交流QQ群:732481539
# 尋找有志同道合的小伙伴,互幫互助,群裡還有不錯的視頻學習教程和PDF電子書!
[x, t] = np.meshgrid(np.array(range(30)) / 28.0, np.arange(0, 575.5, 0.5) / 575 * 17 * np.pi - 2 * np.pi)
p = (np.pi / 2) * np.exp(-t / (8 * np.pi))
u = 1 - (1 - np.mod(3.6 * t, 2 * np.pi) / np.pi) ** 4 / 2
y = 2 * (x ** 2 - x) ** 2 * np.sin(p)
r = u * (x * np.sin(p) + y * np.cos(p))
h = 4 + u * (x * np.cos(p) - y * np.sin(p)) * 3
c = cm.get_cmap('Reds')
surf = ax.plot_surface(r * np.cos(t), r * np.sin(t), h, rstride=1, cstride=1, color='r', # cmap= c,可改變花朵顏色
alpha=0.8, linewidth=0, antialiased=True) # rstride和cstride為橫豎方向的繪圖采樣步長,越小繪圖越精細。
# 花梗
u2 = np.linspace(0, 2 * np.pi, 50) # 把圓分按角度為50等分
h2 = np.linspace(0, 4, 20) # 把高度1均分為20份, 玫瑰花梗高度范圍
x2 = np.outer(0.05 * np.sin(u2), np.ones(len(h2))) # x值重復20次
y2 = np.outer(0.05 * np.cos(u2), np.ones(len(h2))) # y值重復20次
z2 = np.outer(np.ones(len(u2)), h2) # x,y 對應的高度
pole = ax.plot_surface(x2, y2, z2,
cmap=cm.get_cmap('summer')) # cmap=cm.get_cmap('Greens'),cmap=cm.get_cmap('summer'),color='g'
plt.axis('off')
fig.savefig('redRose.png', transparent=True)
plt.show()
效果:
Catalog One 、matplotlib.pyplo
Python How to quickly save pic
In the last class , We designe