% Create legend if requested; base it on the top right plot
if (doleg)
gn = gn(ismember(1:size(gn,1),g),:);
legend(ax(1,cols),gn);
end
I want to put this legend on top right but outside the plot. I have seen in help that there is a command "NorthEastOutside" for putting it out of the plot. But I dont know how to include this option in the code given above. Can anyone help me plz?
one of the solutions
% create your plot
lh=findall(gcf,'tag','legend');
set(lh,'location','northeastoutside');
% but: you'll see that it screws up the plot...
us
Thanks for the reply but I remember one of the guys introduce a new variable say "h" in the same code I mentioned above and for that variable h he made the legend to appear outside the plot......that did not scew the plot but the changings he made are on his computer.....
Could you think how would he have done that.
> Thanks for the reply but I remember one of the guys introduce a new variable say "h" in the same code I mentioned above and for that variable h he made the legend to appear outside the plot......that did not scew the plot but the changings he made are on his computer.....
>
> Could you think how would he have done that.
well, yes...
ph=plot(rand(10,1),'-ks');
ah=axes('position',[.1,.1,.5,.5],'visible','off');
lh=legend('v6',ah,ph,'foo','location','northeastoutside');
% but: you'll see the runtime warning (r2009b)...
% it would probably be easier to set the LEGEND's position prop
% your plot...
lh=findall(gcf,'tag','legend');
lp=get(lh,'position');
set(lh,'position',[.1,.1,lp(3:4)]);
us
----I have tried this but still I have to set the position which takes sometime. I dont say that it is wrong but I am sure my friend just changed one little thing in the following code and automatically legend started to appear outside the graph on top right position and the symmetry of graph was not disturbed....He did not add anything special instead introduced "NorthEastOutside" somewhere in the code given below:
---------------------
Hey I have found the way to put it outside...see the changes I made to the code:
% Create legend if requested; base it on the top right plot
if (doleg)
gn = gn(ismember(1:size(gn,1),g),:);
h=legend(ax(1,cols),gn);
set(h,'Location','NorthEastOutside');
end
I simply set h as the legend and wrote it to be outside the plot.....
But anyways thanksalot for taking interest in my post :)) Keep up the good work "us"....
> % Create legend if requested; base it on the top right plot
> if (doleg)
> gn = gn(ismember(1:size(gn,1),g),:);
> h=legend(ax(1,cols),gn);
> set(h,'Location','NorthEastOutside');
> end
>
> I simply set h as the legend and wrote it to be outside the plot.....
> But anyways thanksalot for taking interest in my post :)) Keep up the good work "us"....
well... this mimics EXACTLY what i told you in my first reply(?)...
lh=findall(gcf,'tag','legend'); % <- instead of returning the handle H...
set(lh,'location','northeastoutside');
% now, since you seem to be happy with the solution(?) - and have actually
% changed the function(!), why not simply add
legend(ax(1,cols),gn,'location','northeastoutside');
us
----------
oh yes you are correct...I just realized that...thanks for ur time