Azzera filtri
Azzera filtri

Display plot/image on fraction of figure area

3 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Walter Roberson
Walter Roberson il 11 Ago 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 Commenti
Will
Will il 11 Ago 2011
Thanks for the two quick answers. I hadn't realized that the size of the plot was set in the axes properties.
Is there any advantage to using uicontrol() over annotation() to make a text box?
Walter Roberson
Walter Roberson il 11 Ago 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.

Accedi per commentare.

Più risposte (1)

Fangjun Jiang
Fangjun Jiang il 11 Ago 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');

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by