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

1 次查看(过去 30 天)
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