How do position coordinates work on a subplot?

25 次查看(过去 30 天)
I have a subplot filled with one video up top and two graphs underneath. In order to get the ratio right I used a subplot(4,4,1:12) for the video, subplot(4,4,13:14) for one graph and subplot(4,4,15:16) for the other. I am now trying to use insertText() and insertShape() to add labels on top of the video but I'm not sure how the position works in those two functions. Can anyone clariffy?

采纳的回答

Walter Roberson
Walter Roberson 2021-1-22
insertText() and insertShape() work with array coordinates, and those are not necessarily the same as axes data coordinates. An array is being written in to, and then in this situation, the array has to be displayed on an axes.
The primary method of displaying an array on an axes is to use image() objects: imagesc() and imshow() both use image() internally. image objects have xdata and ydata properties https://www.mathworks.com/help/matlab/ref/image.html#buqdlnb-x that describe the transformation from array indices to data coordinates. The default mapping is to put the center of the lower left pixel at data coordinates (1,1) and increase by one data unit for each adjacent array coordinate. Other objects in the axes work with data coordinates (except for annotation objects, which are not actually inside the axes.)
It is entirely valid to have an array that is (say) 480 x 640 x 3, and to image() it specifying that the center of the lower left array element is to go at data coordinate (3,10) and that the center of the upper right array element is to go at data coordinate (9.4, 14.4) so that adjacent array elements become 1/100 data units apart, and then to plot(1:15, 10*rand(1,15)) and have the line be drawn across the full image.
Data units in turn get interpreted into physical screen pixels according the the axes Position and Units and whatever containers the axes is nested inside, including the figure position. Typically, if the user grabs the figure and resizes it then nothing needs to change at the lower levels (but the text might start to look bad.)
  6 个评论
Michael Cottingham
Michael Cottingham 2021-1-25
Yea, I got that now... I don't know it just didn't click in my head
Walter Roberson
Walter Roberson 2021-1-26
There is an inherent conflict in how people use arrays and graphics. People very often treat array index (1,1) as the upper left corner of an image when they are building code, and think of increasing y coordinates as being further down in the image. But cartesian coordinates have (0,0) as the lower left and increasing y coordinates being further up away from the bottom. Low y as being top of the image, vs low y being the bottom of the image. Both points of view are valid, but they conflict.
Because of this, the standard image operations image(), imagesc(), and imshow(), check to see if "hold" is on, and if not, they automatically reverse the coordinate system for the Y axes by setting the axes YDir property to 'reverse', so that increasing y coordinates are lower on the display, in keeping with how most people compute arrays when building images.
You can deliberately set YDir to 'normal' so that coordinates increase up going up the display. Both perspectives are "right" -- you just have to be aware of which you are using and how to switch between them.

请先登录,再进行评论。

更多回答(1 个)

dpb
dpb 2021-1-22
编辑:dpb 2021-1-25
It appears that those [x,y] positions are the image indices from the upper left of the image. If you look at the two examples and where the text is inserted, the y position is lower in the image as the position increases and moves to the right as x postion increases. That would be consistent with images in MATLAB on axes with y-axis decreasing.
I don't have the TB so that's just reading the doc and looking at the examples...a little experimentation out to answer the question pretty quickly.

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by