필터 지우기
필터 지우기

gname for labelling lines in a plot

조회 수: 2 (최근 30일)
Felix
Felix 2015년 9월 23일
댓글: Felix 2015년 9월 25일
I want to use gname() to identify the lines of a plot with multiple lines.
I am trying to do it like this:
timeseries = rand(100,3); plot(timeseries); gname({'a','b','c'});
which doesn't work.
If I invert the matrix I can use gname() for labelling, however the plot is obscured:
timeseries = rand(100,3); plot(timeseries'); gname({'a','b','c'})
Would be nice if that could work somehow, I would like to plot hundreds of timeseries in one plot, but the colour labelling doesnt really help to identify them.

채택된 답변

Kelly Kearney
Kelly Kearney 2015년 9월 23일
Maybe setting the ButtonDownFcn of each line to display the name somewhere would work? In this example, I change the axis title:
hax = axes;
changetext = @(str) title(hax, str);
hln = plot(1:3, rand(3,100));
for ii = 1:100
hln(ii).ButtonDownFcn = @(~,~) changetext(num2str(ii));
end
  댓글 수: 3
Kelly Kearney
Kelly Kearney 2015년 9월 24일
For that version, replace
hln(ii).ButtonDownFcn = @(~,~) changetext(num2str(ii));
with
set(hln(ii), 'ButtonDownFcn', @(~,~) changetext(num2str(ii)));
Felix
Felix 2015년 9월 25일
Thank you! It works. For some reason the Axes have a second label from 0.0 to 1.0 overaying the original label.
I also tested your solution on Windows with Matlab 2014b. And there it works perfectly

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

추가 답변 (1개)

Thorsten
Thorsten 2015년 9월 23일
legend({'a', 'b', 'c', 'd'})
  댓글 수: 1
Felix
Felix 2015년 9월 23일
I would like to have an "interactive" solution where I can click on the lines to identify them. When I have 100s of timeseries one plot the Legend becomes useless. Thanks for your comment though

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

카테고리

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