当前位置:   article > 正文

python3d玫瑰花

python3d玫瑰花
  1. from matplotlib import cm
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. class Rose3D:
  5. def __init__(self):
  6. self.fig = plt.figure()
  7. self.ax = self.fig.add_subplot(projection='3d')
  8. def plot(self):
  9. [x, t] = np.meshgrid(np.array(range(25))/24.0, np.arange(0, 575.5, 0.5)/575*17*np.pi-2*np.pi)
  10. p = (np.pi/2)*np.exp(-t/(8*np.pi))
  11. u = 1-(1-np.mod(3.6*t, 2*np.pi)/np.pi)**4/2
  12. y = 2*(x**2-x)**2*np.sin(p)
  13. r = u*(x*np.sin(p)+y*np.cos(p))
  14. surf = self.ax.plot_surface(r*np.cos(t), r*np.sin(t),u*(x*np.cos(p)-y*np.sin(p)), rstride=1, cstride=1,
  15. cmap=cm.Reds_r,linewidth=0, antialiased=True)
  16. # 设置文字内容和显示设置
  17. self.ax.text(-0.3, 0, 1.2, 'love you ~', color='red')
  18. self.ax.axis('off')
  19. plt.show()
  20. # 创建Rose3D对象并绘制立体玫瑰花
  21. rose = Rose3D()
  22. rose.plot()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/111800
推荐阅读
相关标签
  

闽ICP备14008679号