How can I enlarge the legend box-size?
조회 수: 462 (최근 30일)
이전 댓글 표시
Hi,
I am plotting two curves and defining their parameters using the legend. The code is as follows
hleg1 = legend ( ['$ n/n_c = $' num2str(den1)], ['$ n/n_c = $' num2str(den2)] );
set(hleg1,'Interpreter','latex')
set(gca,'fontsize',15)
My problem is that as soon as I change the font size to 15 the box around the legends doesn't expand automatically and I have legends of the curves going outside the legend box. Can anybody suggest something?
댓글 수: 0
채택된 답변
Walter Roberson
2013년 2월 14일
legend() is implemented by creating a new axis, the handle of which is returned. You should be setting Interpreter and fontsize for the text entries rather than the axis.
[hleg1, hobj1] = legend( ...);
textobj = findobj(hobj1, 'type', 'text');
set(textobj, 'Interpreter', 'latex', 'fontsize', 15);
Then if you find you need to, set() the Position property of hleg1.
댓글 수: 2
Walter Roberson
2013년 2월 15일
You have a legend with two entries. The second value returned by legend() is the handles to the objects that went up to make the legend, including the text objects. The findobj() reduces the list down to just the text objects. The set() then affects all of those text objects. So already this code works for legends with multiple entries.
추가 답변 (2개)
Azzi Abdelmalek
2013년 2월 14일
편집: Azzi Abdelmalek
2013년 2월 14일
set(hleg1,'position',[0 0 0.2 0.2])
In general
set(hleg1,'position',[x0 y0 width height])
댓글 수: 2
Max Riedel
2016년 4월 6일
A simple workaround is to put additional spacing after the text.
E.g., by using \quad:
hleg1 = legend ( ['$ n/n_c = $' num2str(den1) '$\quad$'], ['$ n/n_c = $' num2str(den2) '$\quad$'] );
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!