Display plot/image on fraction of figure area
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Walter Roberson
le 11 Août 2011
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 commentaires
Walter Roberson
le 11 Août 2011
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.
Plus de réponses (1)
Fangjun Jiang
le 11 Août 2011
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 commentaires
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!