Python 在三维轴上打印二维图像

Python 在三维轴上打印二维图像,python,matplotlib,Python,Matplotlib,使用matplotlib是否可以拍摄某个物体的二维图像并将其放置在三维图形中?我想拍摄一张2D图像,并将其放置在z位置0处。然后,我想根据我正在进行的计算,沿着z轴分别移动图像中的其他像素 如果您的图像是彩色图像,则必须首先确保它是索引图像。这意味着您只能有2d矩阵(而不能有RGB组件的3个矩阵)。命令rgb2ind可以提供帮助 然后,您可以直接以3D方式显示图像。使用“网格”或“冲浪”命令 您还可以使用角度和方位角调整透视图。例如: 那么使用诸如Axes3D.plot\u surface()之

使用matplotlib是否可以拍摄某个物体的二维图像并将其放置在三维图形中?我想拍摄一张2D图像,并将其放置在z位置0处。然后,我想根据我正在进行的计算,沿着z轴分别移动图像中的其他像素

如果您的图像是彩色图像,则必须首先确保它是索引图像。这意味着您只能有2d矩阵(而不能有RGB组件的3个矩阵)。命令rgb2ind可以提供帮助

然后,您可以直接以3D方式显示图像。使用“网格”或“冲浪”命令

您还可以使用角度和方位角调整透视图。

例如:


那么使用诸如Axes3D.plot\u surface()之类的工具可以处理实际的二维图像吗?我有点搞不懂怎么画。给它一个x坐标、y坐标和z值的数组似乎不起作用。但这对实际图像是否正确?不仅仅是分数?我想尝试在网格中放置一个图像…例如.png、.jpg等。另一个示例将ax.plot_曲面的第三个参数设置为点z。
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.gca(projection='3d')

# Plot a sin curve using the x and y axes.
x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi) / 2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='curve in (x,y)')

# Plot scatterplot data (20 2D points per colour) on the x and z axes.
colors = ('r', 'g', 'b', 'k')

# Fixing random state for reproducibility
np.random.seed(19680801)

x = np.random.sample(20 * len(colors))
y = np.random.sample(20 * len(colors))
c_list = []
for c in colors:
    c_list.extend([c] * 20)
# By using zdir='y', the y value of these points is fixed to the zs value 0
# and the (x,y) points are plotted on the x and z axes.
ax.scatter(x, y, zs=0, zdir='y', c=c_list, label='points in (x,z)')

# Make legend, set axes limits and labels
ax.legend()
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

# Customize the view angle so it's easier to see that the scatter points lie
# on the plane y=0
ax.view_init(elev=20., azim=-35)

plt.show()