Display plot/image on fraction of figure area
2 次查看(过去 30 天)
显示 更早的评论
Is there a way to plot to only a portion of a figure window? I want to create a plot in a function and add a fairly large annotation in a text box. However, I'd prefer it if the plot only took up around 80% of the plot and the text box took up 20% (in terms of width). Right now, the text box covers up part of the plot. I can think of some clunky work arounds, like padding my plot so that the text box covers up filler data, but I'd prefer a more straightforward solution if there is one.
0 个评论
采纳的回答
Walter Roberson
2011-8-11
Work out the width of the text box, including the width required for the scroll bar; work out the total width available; subtract the two and subtract a margin; set the axes position to be only as wide as is available.
You can find out how wide a text box "would like to be" by setting up a dummy text box, and using textwrap() on the uicontrol together with the proposed string. The resulting control will have an Extent field that will reflect how big MATLAB would "like" the box to be. If you do not plan to make the box as tall as the recommendation, then add a margin of roughly one character-with (19-ish pixels) to take in to account the scroll bar. That information in hand, delete the dummy text box and set() the real box to the dimensions you just calculated.
2 个评论
Walter Roberson
2011-8-11
uicontrol() makes it easier to change the text.
uicontrol has the possibility of scrolling the text. Though to do that, you should use an edit box instead of a text box, and set the 'enable' property to 'disable' (*not* 'off')
uicontrol makes it easier to calculate the width of the widest line; annotation is more difficult, especially if you change fonts or character set.
更多回答(1 个)
Fangjun Jiang
2011-8-11
fig=figure;
h_axes=axes('parent',fig,'position',[.1 .1 .8 .7]);
plot(h_axes,1:10);
h_text=uicontrol('style','text','parent',fig,'position',[147 362 227 33]);
set(h_text,'string','This is the text');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!