【发布时间】:2011-04-12 18:44:28
【问题描述】:
我有一个二维散点图,我想在原点显示一个图像(不是彩色正方形,而是实际图片)。有没有办法做到这一点?
我还将绘制一个 3-D 球体,我希望图像也显示在原点。
【问题讨论】:
我有一个二维散点图,我想在原点显示一个图像(不是彩色正方形,而是实际图片)。有没有办法做到这一点?
我还将绘制一个 3-D 球体,我希望图像也显示在原点。
【问题讨论】:
函数IMAGE 是您正在寻找的。这是一个例子:
img = imread('peppers.png'); %# Load a sample image
scatter(rand(1,20)-0.5,rand(1,20)-0.5); %# Plot some random data
hold on; %# Add to the plot
image([-0.1 0.1],[0.1 -0.1],img); %# Plot the image
IMAGE 函数不再适用,因为除非从正上方(即从正 z 轴)查看轴,否则不会显示图像。在这种情况下,您必须使用SURF 函数创建一个 3-D 表面,并将图像纹理映射到其上。这是一个例子:
[xSphere,ySphere,zSphere] = sphere(16); %# Points on a sphere
scatter3(xSphere(:),ySphere(:),zSphere(:),'.'); %# Plot the points
axis equal; %# Make the axes scales match
hold on; %# Add to the plot
xlabel('x');
ylabel('y');
zlabel('z');
img = imread('peppers.png'); %# Load a sample image
xImage = [-0.5 0.5; -0.5 0.5]; %# The x data for the image corners
yImage = [0 0; 0 0]; %# The y data for the image corners
zImage = [0.5 0.5; -0.5 -0.5]; %# The z data for the image corners
surf(xImage,yImage,zImage,... %# Plot the surface
'CData',img,...
'FaceColor','texturemap');
请注意,此表面在空间中是固定的,因此当您旋转轴时,图像不会始终直接面向相机。如果您希望纹理贴图表面自动旋转,使其始终垂直于相机的视线,这是一个复杂得多的过程。
【讨论】: