Place text below patch object

조회 수: 16 (최근 30일)
Rob L
Rob L 2019년 4월 11일
답변: Rob L 2019년 4월 23일
I have plotted a triangle as a patch object on my figure.
I wish to add a text box uicontrol object just below it to add information. How can I determine the location of the triangle in the figure to use as a location for the text box ?
[MOVED from section for answers - Jan]
I wanted to have a non-default background colour which is an option for uicontrol / text but not text.
  댓글 수: 1
Jan
Jan 2019년 4월 11일
Why do you want an uicontrol text box and not a text() object, which uses the coordinates of the axes directly?

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

채택된 답변

Jan
Jan 2019년 4월 12일
편집: Jan 2019년 4월 12일
Of course text allows to set the background color:
axes
text(0.5, 0.5, 'Hello', ...
'Color', 'r', 'BackgroundColor', 'c')
Therefore I'm still convinced, that a text object is much easier.
  댓글 수: 2
Jan
Jan 2019년 4월 23일
[MOVED from section for answers] Rob L wrote:
Thanks for your suggestion - the text object is indeed easier. However, the appearance of the text in my case is too large once the background color is set (the size / extent of the box is not accessible as a property other than by sizing the actual text). There is greater flexibility to control the obect when created as a uicontrol.
The application usinmg the above is a complex GUI with a mixture of axes, uicontrol, text and other objects. In general, I would wish to determine the location of any object in the GUI so that I can add further information in the appropriate location. Being able to ascertain a common location across all obects gives the flexibility needed.
Jan
Jan 2019년 4월 23일
"the size / extent of the box is not accessible as a property other than by sizing the actual text"
I cannot confirm this opinion. Use the property 'Margin' to control the space around the text within the text box. The text object has more flexibility than an uicontrol.
You mention, that you want to determine the location - but in which coordinate system? With text it is trivial to use the local coordinates of an axes object, with an annotation or an uicontrol you can use the pixel coordinates relative to the figure. You can determine the position on the screen or on multiple screens easily also. The relation between the axes and the figure coordinates can be determined by simple maths in the 2D case. With 3D axes the projection method matters.
Maybe the functions getpixelposition (link) and setpixelposition (link) will help you.

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

추가 답변 (1개)

Rob L
Rob L 2019년 4월 23일
The functionality I need is indeed what is offered by the two linked functions.
Whilst the specific example may have been better served by a text object with the suggested properties, these functions seem to allow greater flexibility for a GUI contating axes, patch object and uicontrols.
Many thanks.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by