How to plot an image(.bmp) in a graph?

Hello,
I have a 2-D plot and on the top right corner of the plot, I want to display an image (picture).
Is there any way to do this?

 採用された回答

Walter Roberson
Walter Roberson 2013 年 12 月 20 日

0 投票

You can use image()
image(x,y,C), where x and y are two-element vectors, specifies the range of the x- and y-axis labels, but produces the same image as image(C). This can be useful, for example, if you want the axis tick labels to correspond to real physical dimensions represented by the image. If x(1) > x(2) or y(1) > y(2), the image is flipped left-right or up-down, respectively. It can also be useful when you want to place the image within a set of axes already created. In this case, use hold on with the current figure and enter x and y values corresponding to the corners of the desired image location. The image is stretched and oriented as applicable.

5 件のコメント

afrya
afrya 2013 年 12 月 20 日
Thanks for your answer, I used the function image and it works well.The image appears in the graph.However, even if I changes the coordinates of the postion of the image, I didn't manage to display the image on the top right corner of the figure window. Do you have an idea how to do that?
Walter Roberson
Walter Roberson 2013 年 12 月 21 日
Are you trying to change have the image display in the top right corner of the plot (i.e., the axes), or have it display in the top right corner of the figure window?
The coordinates you use for x and y should be "data" coordinates -- the same units used to position lines on axes.
afrya
afrya 2014 年 1 月 3 日
I just want to have it display in the top right corner of the figure window
Image Analyst
Image Analyst 2014 年 1 月 3 日
So you have like a plot of a curve or something and you want a little image, like a logo, in the upper right corner? Did you try the plot first and then put "hold on" and then display the image with the proper data coordinates?
Walter Roberson
Walter Roberson 2014 年 1 月 3 日
Draw the plot. Then
axis equal %so images show up with right aspect ratio
set(gca, 'XLimMode', 'manual', 'YLimMode', 'manual');
xl = get(gca, 'XLim');
yl = get(gca, 'YLim');
sizefactor = 0.9; %play with this to get right size, smaller is bigger image
imgx = [sizefactor * xl(2) + (1-sizefactor) * xl(1), xl(2)];
imgy = [sizefactor * yl(2) + (1-sizefactor) * yl(1), yl(2)];
image(imgx, imgy, YourImage);

サインインしてコメントする。

その他の回答 (1 件)

Wei
Wei 2013 年 12 月 20 日

0 投票

you can use:
subplot(2,2,2)
to manage to display the image on the top right corner of the figure window.

カテゴリ

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by