placing text outside the axis in the figure

조회 수: 92 (최근 30일)
sermet
sermet 2016년 2월 19일
답변: Star Strider 2016년 2월 19일
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
Ingrid
Ingrid 2016년 2월 19일
why not just use the title command to show this information?

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 2월 19일
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:')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by