Find text graphics extent in axes data units

7 次查看(过去 30 天)
I need to show and hide labels on polygons, if the label too large for the polygon I need to hide it. If the label is smaller than the polygon, I show it again.
To do this I found a way that works some of the time, by using a text extent property.
label = text(ax,0,0,'A','Visible','off');
extent = get(label,'Extent');
delete(label);
% Convert Extent to area...
extent_x = [0 extent(3) extent(3) 0];
extent_y = [extent(4) extent(4) 0 0];
characterAreaMapUnits = polyarea(extent_x,extent_y);
This seems to break down when I move the camera in a way that is too "3D," when this happens the extent property of the the text object is returned as [NaN NaN NaN NaN]. The documentation doesn't tell me that this can happen so I can't be sure what made it happen. Is there a reason this is happening? is there a better way to find the area of a text object?
This never seems to happen when I change the "Units" of the text object to anthing other than "data", but I need this in data units to properly compare it to the polygon that label is labelling.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by