Is it possible to create a selective legend in a multiplot graph?

조회 수: 1 (최근 30일)
Alon Rozen
Alon Rozen 2018년 12월 31일
댓글: Alon Rozen 2019년 1월 1일
Hi all,
I already asked this question in somewhat less clear manner. So now I added a clear code:
I have two sets of data - A_Data and B_Data.
In each set the data has a data ID. So I have A_IDs and B_IDs.
I plot all on the same axis:
% Prepare:
H = My_Axis;
Num_Of_A = length(A_IDs);
Num_Of_B = length(B_IDs);
Lgnd_Cell = cell(Num_Of_A+Num_Of_B,1);
Lgnd_Indx = true(Num_Of_A+Num_Of_B,1)
% Plot A data:
for i = 1:Num_Of_A
Data = Data_A{i};
plot3(H,Data(:,1),Data(:,2),Data(:,3),['Certain_Shape' 'Certain_Color']);
hold on;
Lgnd_Cell{i} = ['A Data ' num2str(A_IDs(i))];
Lgnd_Indx(i) = Determine_If_To_Show_This_Data_Legend(Data);
end
% Plot B data:
for i = 1:Num_Of_B
Data = Data_B{i};
plot3(H,Data(:,1),Data(:,2),Data(:,3),['Certain_Shape' 'Certain_Color']);
hold on;
Lgnd_Cell{Num_Of_A+i} = ['A Data ' num2str(B_IDs(i))];
Lgnd_Indx(Num_Of_A+i) = Determine_If_To_Show_This_Data_Legend(Data);
end
Now, based on 'Lgnd_Indx' I want to create a selective legend.
Is it possible?
Thanks,
Alon
  댓글 수: 4
Alon Rozen
Alon Rozen 2018년 12월 31일
The logic dosen't matter because it is not the source of the problem. The source is that the legend command marks the legend items orderly acording to their mark and color. If you ommit one the mark and color that you get belong to it and not to the next plot. So the legend will not corrlate the plots and their right mark + color.

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 12월 31일
record the handles returned by plot3. Index them by your Indx array as your first parameter to legend and index the cell by the same as your second parameter to legend
  댓글 수: 1
Alon Rozen
Alon Rozen 2019년 1월 1일
I tried the following:
I created a cell array 'Plt_Hndl' which record the handles returned by plot3. This is the code:
Plt_Hndl{end+1} = plot3(......);
I also collected the legends I need into 'Lgnd_Cell';
To make things simple I had only two plot handles and two strings as legends.
Next I tried:
legend(Plt_Hndl,Lgnd_Cell);
It didn't work.
It can be done?

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

카테고리

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

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by