赞
踩
七夕就要来了,不论你是不是一个人,都祝你开学快乐~~~
可自定义输入内容
代码:
- """
- * @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()
效果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。