How to control appearance of certain graphs legend in a multi graph plot?

1 Ansicht (letzte 30 Tage)
Alon Rozen
Alon Rozen am 19 Dez. 2018
Kommentiert: Alon Rozen am 19 Dez. 2018
Hi all,
I have the following code which produce a multi fraph plot on an axes which I identify as 'H'
Legend_Data = cell(Some_Number);
for i = 1:Some_Number
plot3(H,X,Y,Z,[Marker,Color]);
Legend_Data{i} = 'Some text';
end
'H' is the axes (in a GUI) in which I want to plot all the graphs.
In each iteration the vectors X,Y,Z are different as well as the sting 'Some text'. Also, the marker used for the graph and its color are changed.
At the end, based on some logic, I wand to desplay a legend but to exclude some of entries. Of course, I want the remaining data to be correctly associated with the right graphs.
I read some sugesstions over the net but couldn't figure out how to apply them to this code. Most of them were related to cases where all graphs are ploted at once.
Can it be done?
Thanks in advance,
Alon
  7 Kommentare
Alon Rozen
Alon Rozen am 19 Dez. 2018
I don't knoe beforehand what plots I will need. It depends on some calculations. So I can't prepare exactly the ones I will want to use. Sometimes it will be this number and sometime a different number. I will find the i's which suit presentation. Can I automate the 'legend' command?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

madhan ravi
madhan ravi am 19 Dez. 2018
Comment reposted as answer:
x=rand(10,5);
y=rand(10,5);
z=rand(10,5);
h=cell(1,5);
c={'a','b','c','d','e'};
for i = 1:5
h{i}=plot3(x(:,i),y(:,i),z(:,i));
hold on
end
legend([h{1} h{3} h{5}],c{1},c{3},c{5})
  3 Kommentare
madhan ravi
madhan ravi am 19 Dez. 2018
Bearbeitet: madhan ravi am 19 Dez. 2018
can you give an example of your legend contents so that the solution can be narrowed down ?
Alon Rozen
Alon Rozen am 19 Dez. 2018
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_A
Data = Data_A{i};
plot3(H,Data(:,1),Data(:,2),Data(:,3),['Certain_Shape' 'Certain_Color']);
hold on;
Lgnd_Cell{Num_Of_A+i} = ['A Data ' num2str(A_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
Hope it explains.
Alon

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by