如何使用 Python 在 3D 图形表面上绘制图像文件? - 不绘制为平面

2023-11-21

有没有办法使用 Python 在 3D 图形表面上绘制图像文件?

我已经看到了几种将其绘制为平面的方法,但我希望图像覆盖在绘图的表面上。这可能吗?


您需要将表面的颜色更改为图像的颜色,如@sarwar 建议的示例所示。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.cbook import get_sample_data
from matplotlib._png import read_png
import numpy as np

fn = get_sample_data("lena.png", asfileobj=False)
img = read_png(fn)

x, y = np.mgrid[0:img.shape[0], 0:img.shape[1]]

ax = plt.gca(projection='3d')
ax.plot_surface(x, y, np.sin(0.02*x)*np.sin(0.02*y), rstride=2, cstride=2,
                facecolors=img)
plt.show()

这给出了结果

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Python 在 3D 图形表面上绘制图像文件? - 不绘制为平面 的相关文章

随机推荐