user2175762
user2175762

Reputation: 271

Specify location of a textbox in a Matlab plot

I am looking for a smart way to make sure that the textbox I am including in my plot is in the top right or top left corner. Just like the legend for example. Even if you rescale your plot it sticks to the original location. The command for that is 'Location', 'NorthWest' for example. But that doesnt work for textboxes. Maybe someone has an intelligent solution.

Thanks

Upvotes: 1

Views: 4417

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

You can achieve that using normalized units for the 'position' property of the textbox. To do that, set the 'units' property to 'normalized'. You then choose the 'position' values between 0 and 1.

The problem is that the 'position' property defines not only position, but also size. So in addition to the textbox remaining in the desired (normalized) position, its size will be rescaled. That may be desired behaviour or not.

uicontrol('style','text', 'units','normalized', ...
    'position',[.83 .88 .1 .05], 'string','Hello')

You can also set 'FontUnits' to 'normalized' and then choose 'FontSize' in normalized units if you want the text (not just the textbox) to be resized.

Upvotes: 1

Related Questions