필터 지우기
필터 지우기

Applying labels to specific data points

조회 수: 129 (최근 30일)
K M
K M 2018년 1월 15일
편집: Adam Danz 2019년 12월 13일
I have a scatter plot of x = [0 1 2] and y = [8 7 6] with corresponding labels in N = ['A', 'B', 'C']. I know how to add labels to all the data points using the text() or labelpoints() functions but I was wondering if there was a way to apply labels to certain data points only, e.g. (1,7) and (2,6)?
  댓글 수: 2
Greg
Greg 2018년 1월 15일
Share the (relevant) code you currently have so we know what to work with.
Also, what is labelpoints? If you're using non-bundled functions, it helps to say so.
K M
K M 2018년 1월 16일
편집: Adam Danz 2019년 12월 13일

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

채택된 답변

Greg
Greg 2018년 1월 15일
If you're already using text, just throw an index into the mix... Assuming you have:
text(x,y,N);
Change it to:
N = ['A';'B';'C']; % If "N" is not cellstr or string datatype, must be column vector
labelinds = [2,3];
text(x(labelinds),y(labelinds),N(labelinds));
  댓글 수: 2
K M
K M 2018년 1월 15일
Thanks for your help, N is a string array. I was using an index, the labels were just too long so it looked like they had been randomly placed. Is it possible for me to change the colour of the labelled data points? The data points are tightly clustered so it is hard to see which points the labels are referring to.
Greg
Greg 2018년 1월 16일
편집: Greg 2018년 1월 16일
Objects returned by the text function have a 'Color' property. I doubt you can set each one to a unique color in a single call to text, but you can loop through the output afterward.
htext = text(...);
C = [1,0,0; ... red
0,1,0]; % green
for itext = 1:length(labelinds)
htext(itext).Color = C(itext,:);
end

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by