fork download
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from matplotlib.animation import FuncAnimation
  4. from mpl_toolkits.mplot3d import Axes3D
  5.  
  6. # 创建图形和3D坐标轴
  7. fig = plt.figure(figsize=(6, 6))
  8. ax = fig.add_subplot(111, projection='3d')
  9. ax.set_axis_off() # 关闭坐标轴
  10.  
  11. # 生成球体的数据
  12. u = np.linspace(0, 2 * np.pi, 100)
  13. v = np.linspace(0, np.pi, 100)
  14. x = 10 * np.outer(np.cos(u), np.sin(v))
  15. y = 10 * np.outer(np.sin(u), np.sin(v))
  16. z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
  17.  
  18. # 绘制球体表面
  19. sphere = ax.plot_surface(x, y, z, color='lightblue', alpha=0.8)
  20.  
  21. # 设置初始视角
  22. ax.view_init(elev=30, azim=30)
  23.  
  24. # 动画更新函数
  25. def update(frame):
  26. ax.view_init(elev=30, azim=frame)
  27. return fig,
  28.  
  29. # 创建动画
  30. ani = FuncAnimation(fig,
  31. update,
  32. frames=np.arange(0, 360, 1),
  33. interval=50,
  34. blit=False)
  35.  
  36. # 显示窗口
  37. plt.show()
  38.  
Success #stdin #stdout 1.02s 66396KB
stdin
Standard input is empty
stdout
Standard output is empty