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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by