Ste*_*rch 7 python plot matplotlib
有没有办法使用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()
Run Code Online (Sandbox Code Playgroud)
结果就是
