Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
three legends on one plot

Subject: three legends on one plot

From: J G

Date: 15 Jun, 2011 01:25:21

Message: 1 of 2

Hi, I'm trying to plot a scatter graph with three different legends. Ideally I would like one legend with three subtitles but I don't think that's possible so I've tried to create three separate ones. However, when setting the location to 'NorthEastOutside', 'EastOutside' and 'SouthEastOutside' respectively, they do not line up. Presumably this is because the non-visible axes (ah2 and ah3) are not the same size as ah1? Any suggestions?
Thanks.


h(1) = scatter(A,B,'blackp');
hold on
h(2) = scatter (C,D,'black^');
h(3) = scatter (E,F,'blackd');
h(4) = scatter (I,J,'blue^');
h(5) = scatter (G,H,'red.');

% Block 1
% Axes handle 1 (this is the visible axes)
ah1 = gca;
% Legend at axes 1
legend(ah1,h(1:3),'y1','y2','y3',1,'location','NorthEastOutside')
v = get(legend,'title');
set(v,'string','t = 0.1');

% Block 2
% Axes handle 2 (unvisible, only for place the second legend)
ah2=axes('position',get(gca,'position'), 'visible','off');
% Legend at axes 2
legend(ah2,h(3),'y4',2,'location','EastOutside')
w = get(legend,'title');
set(w,'string','t = 0.1');

% Block 3
% Axes handle 3 (unvisible, only for place the third legend)
ah3=axes('position',get(gca,'position'), 'visible','off');
% Legend at axes 3
legend(ah3,h(5),'y5',3,'location','SouthEastOutside')

Subject: three legends on one plot

From: J G

Date: 15 Jun, 2011 03:56:04

Message: 2 of 2

Solved this problem by setting the legend position manually... not sure why I didn't think of this before!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us