Text object out of the axes

12 ビュー (過去 30 日間)
Giuela
Giuela 2020 年 9 月 22 日
コメント済み: Ameer Hamza 2020 年 9 月 22 日
On my axes I draw an item (for example a circle) and close to it I put a text object as the name of the item.
When I change the axes limits in order to change the view, like a paneling, if the item is not in the new axis range is not drawn, but the text is drawn also if its position is completely out of the axis range.
Te effect is that the text could be in everey place of the figure.
Is there a way to not draw the text if it's out of the axes area?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 22 日
The only way I found is to create an event listener, and inside the callback function, check if the text object is outside the axes limits. If the text is outside, then set the 'visible' property to 'off'. https://www.mathworks.com/matlabcentral/answers/92886-how-do-i-create-a-callback-function-which-gets-executed-whenever-the-xlim-value-of-axes-changes

その他の回答 (1 件)

Giuela
Giuela 2020 年 9 月 22 日
Thank you , Amreer, it works.
I don't understand why the text object behavior cannot be the same of the patch one. They're both graphical objects, but they're treated differently when you change the axis limits.
Thank you
  1 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 9 月 22 日
Actually, the text objects are used for a lot of things. For example, xlabel, ylabel, and title of axes are all text objects. Therefore, it is designed such that it remains visible as long as the x y coordinates can are within the figure limits. It does disappear if you change the axes limits by a large amount.
For example
ax = axes();
plot(1:10);
text(ax, 5, 5, 'ABCD');
It will display ABCD at (5, 5). But if you change the x-limits to
ax.XLim = [10, 20];
the text will not longer be visible.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by