Adjust plot to image size

조회 수: 4 (최근 30일)
Gurbir Sandhu
Gurbir Sandhu 2020년 12월 5일
댓글: Walter Roberson 2020년 12월 6일
Hi Everyone,
I want to plot a graph over an image. the image is 750X800 but my graph goes from 0 to 20 on x axis and 0 to 36 on y axis. As a result the graph looks very small and shrinked up. How can I adjust the size of graph so it looks normal over the image.

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 6일
If you use image() or imagesc() to draw the image, then you can specify leading parameters that are boundaries of where to place the image in data coordinates.
image(xlocation, ylocation, ImageArray)
If you use image() or imagesc() or imshow() then you can instead pass in 'XData' and 'YData' options to control the positions:
image(ImageArray, 'XData', xlocation, 'YData', ylocation)
The x location you pass in is a vector of values. The first value is used to control the x data coordinate at which the center of the bottom left pixel is to be placed. The last value is used to control the x data coordinate at which the center of the top right pixel is to be placed. Any other entries in the vector are ignored. Likewise, the y vector is used to control the y data coordinate of the center of bottom left, and center of top right.
I emphasize: coordinates of centers . So if you give a data coordinate of 0 then do not be surprised to see the last pixel sticking out past 0.
  댓글 수: 4
Gurbir Sandhu
Gurbir Sandhu 2020년 12월 6일
Thanks Walter. This helps a lot.
Walter Roberson
Walter Roberson 2020년 12월 6일
Notice the slight border shift, most noticeable at the bottom. If i recall correctly, the default for image() is to put the center of the bottom left pixel at (1,1)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by