Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Consolidating Many Legend Entries Into One

400 views
Skip to first unread message

Camron Call

unread,
Apr 8, 2009, 3:22:26 PM4/8/09
to
I have a figure where I plot four sets of data each with 8 or 9 individual rows. Each data set has a color that represents it. I would like to have only 4 entries in the legend, one for each color. But currently, the legend has an entry for each row of data resulting in close to 35 entries or so which makes everything way too cluttered since they represent similar data.

Currently, I am using the figure editor to fine tune this, but I could implement a solution easily enough in script as well.

Idin Motedayen-Aval

unread,
Apr 8, 2009, 6:44:32 PM4/8/09
to
Camron Call wrote:
> I have a figure where I plot four sets of data each with 8 or 9 individual rows. Each data set has a color that represents it. I would like to have only 4 entries in the legend, one for each color. But currently, the legend has an entry for each row of data resulting in close to 35 entries or so which makes everything way too cluttered since they represent similar data.
>
> Currently, I am using the figure editor to fine tune this, but I could implement a solution easily enough in script as well.

Hi Camron,
A while ago I did something like this and found some example code in the
MATLAB doc (under "Controlling Legends"). Here's my code:

%% Create dummy data
SNRs = 0:1:25;
dummy_data = [10.^(-SNRs); 5.^(-SNRs); 20.^(-SNRs)];
%% Plot theoretical curves
h_lines = semilogy(SNRs,dummy_data,':');
hold on
%% Plot simulation results
simLines = semilogy(SNRs, dummy_data,'*');

%% Add Legend
% Do MATLAB graphics magic to create concise legend
% See "Controling Legends" in MATLAB doc

% group lines together
simGrp = hggroup('DisplayName','Simulation');
theoGrp = hggroup('DisplayName','Theoretical');
set(simLines,'Parent',simGrp)
set(h_lines,'Parent',theoGrp)
set(get(get(simGrp,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on'); % Include this hggroup in the legend
set(get(get(theoGrp,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','on'); % Include this hggroup in the legend
legend show


HTH,
Idin

--
Idin Motedayen-Aval
The MathWorks, Inc.
zq=[4 2 5 -15 -1 -3 24 -57 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2];
char(filter(1,[1,-1],[105 zq])), clear zq

0 new messages