placing text outside the axis in the figure

72 visualizzazioni (ultimi 30 giorni)
figure(1); hold on
scatter(1, 1, 100, 'k', 'o')
scatter(1, 2, 100, 'k', '+')
h = legend('circle', 'Plus', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
text=('information:')
I need to place text string outside the axis in the figure. If it is not possible I need to insert text right below the legend. Scatter data is not constant all the time so the location of the text wouldn't depend on the axis data.
Thanks in advance
  1 Commento
Ingrid
Ingrid il 19 Feb 2016
why not just use the title command to show this information?

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 19 Feb 2016
I don’t know where you want to put them outside the axes, so this code puts them below the legend instead. It is adaptive, and uses the 'Position' property of the legend and the axis limits to place the text object. You will have to experiment with it to get the result you want:
figure(1); hold on
scatter(1, 1, 100, 'k', 'o')
scatter(1, 2, 100, 'k', '+')
h = legend('circle', 'Plus', 'Location', 'NorthEast');
set(h, 'FontSize', 14)
axis([0 3 0 3])
axlim = get(gca, 'XLim'); % Get ‘XLim’ Vector
aylim = get(gca, 'YLim'); % Get ‘YLim’ Vector
legpos = get(h, 'Position'); % Get ‘legend’ 'Position' Vector
x_txt = min(axlim) + diff(axlim)*legpos(1) + 0.05*diff(aylim); % Set ‘x’-Coordinate Of Text Object
y_txt = min(aylim) + diff(aylim)*legpos(2) - 0.01*diff(aylim); % Set ‘y’-Coordinate Of Text Object
text(x_txt, y_txt, 'information:')

Più risposte (0)

Categorie

Scopri di più su Graphics Object Properties 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