fill([0 1 1], [0 1 0], [.9 .9 .9]); hold on
plot(rand(5, 1), 'b');
plot(rand(5, 1), 'r');
plot(rand(5, 1), 'g'); hold off
h = legend('fill', 'line one', 'line two', 'line three');
%# find handles of lines inside legend that have a non-empty tag
hLegendLines = findobj(h, 'type', 'line', '-and', '-regexp','Tag','[^'']');
set(hLegendLines, 'XData', [.2, .3])
%# find handle of patch inside legend
hLegendPatch = findobj(h, 'type', 'patch');
set(hLegendPatch, 'XData', [.2, .2, .3, .3])
РЕДАКТИРОВАТЬ : (ответ на комментарии)
Вы можете управлять размером легенды, установив свойство Position
. Тем не менее, кажется, что легенда подходит к своему содержанию настолько плотно, насколько это возможно по умолчанию, поэтому вы можете сделать его больше, но не меньше (попробуйте изменить размер с помощью мыши):
p = get(h,'Position'); p(3)=0.1;
set(h, 'Position',p);
![alt text](https://i.stack.imgur.com/FvO5n.png)
Другой способ - уменьшить размер шрифта, используемого для надписей:
h = legend('fill', 'line one', 'line two', 'line three')
set(h, 'FontSize',6); %# do this before changing the other stuff
![alt text](https://i.stack.imgur.com/dF1fL.png)