How do I insert an image in my 2-D and 3-D plots in MATLAB 8.2 (R2013b)?
조회 수: 23 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2016년 8월 25일
답변: MathWorks Support Team
2016년 8월 25일
I want to display an image inside a 2-D plot and a 3-D plot. How can I do it?
채택된 답변
MathWorks Support Team
2018년 3월 29일
For 2-D plots:
You can use the function IMAGE.
The following example plots an image at the center of a scatter plot:
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
For 3-D plots:
The IMAGE function is no longer appropriate.
In this case you will have to create a 3-D surface using the SURF function and texture map the image onto it.
The following example shows how to put an image in the middle of a 3-D scatter plot:
[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');
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!