Place text below patch object

13 views (last 30 days)
Rob L
Rob L on 11 Apr 2019
Answered: Rob L on 23 Apr 2019
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 Comment
Jan
Jan on 11 Apr 2019
Why do you want an uicontrol text box and not a text() object, which uses the coordinates of the axes directly?

Sign in to comment.

Accepted Answer

Jan
Jan on 12 Apr 2019
Edited: Jan on 12 Apr 2019
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 Comments
Jan
Jan on 23 Apr 2019
[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 on 23 Apr 2019
"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.

Sign in to comment.

More Answers (1)

Rob L
Rob L on 23 Apr 2019
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.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!