Filter löschen
Filter löschen

placing text outside the axis in the figure

78 Ansichten (letzte 30 Tage)
sermet
sermet am 19 Feb. 2016
Beantwortet: Star Strider am 19 Feb. 2016
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 Kommentar
Ingrid
Ingrid am 19 Feb. 2016
why not just use the title command to show this information?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Star Strider
Star Strider am 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:')

Weitere Antworten (0)

Kategorien

Mehr zu Graphics Object Properties finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by