鱼C论坛

 找回密码
 立即注册
查看: 3305|回复: 6

[Python] 求助求助,已知三列数据怎么画出三维曲面图

[复制链接]
发表于 2024-4-28 23:01:29 | 显示全部楼层
是要这个效果不:

CBBqrPTTTb.png

源代码:

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from mpl_toolkits.mplot3d import Axes3D

  4. # 数据准备
  5. x = np.linspace(-5, 5, 100)
  6. y = np.linspace(-5, 5, 100)
  7. x, y = np.meshgrid(x, y)
  8. z1 = np.sin(np.sqrt(x**2 + y**2))
  9. z2 = np.cos(np.sqrt(x**2 + y**2))

  10. # 绘制
  11. fig = plt.figure()
  12. ax = fig.add_subplot(111, projection='3d')

  13. # 绘制两个曲面
  14. surf1 = ax.plot_surface(x, y, z1, cmap='viridis', alpha=0.5)
  15. surf2 = ax.plot_surface(x, y, z2, cmap='plasma', alpha=0.5)

  16. # 设置标签和标题
  17. ax.set_xlabel('X Coordinates')
  18. ax.set_ylabel('Y Coordinates')
  19. ax.set_zlabel('Z Values')
  20. ax.set_title('Multiple 3D Surface Plots')

  21. # 显示图形
  22. plt.show()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-10-20 03:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表