Legend - position command & printing

조회 수: 3 (최근 30일)
Thomas
Thomas 2014년 3월 19일
답변: Kelly Kearney 2014년 3월 19일
Hi,
I am having some issues with positioning the legend manually. It seems that wen I set the 'position' property manually something goes bad or at least behaves strangely.
Take this example:
figure
hold on
h(1) = plot(1,1,'.');
h(2) = plot(1,1,'o');
h(3) = plot(1,1);
legHand = legend(h,{'daasdadsad' 'asdfasdf' 'asdfdf'});
set(legHand,'position',get(legHand,'position')) % comment or uncomment this
print(gcf,'-dpng','-r600','test.png')
I think that when I set the position of the legend by the values from get(position) then the legend should not change. But in fact it does change position as well as the spacing between the lines of the legend. Is there a reason for this behavior?
For a more complex plot this becomes somewhat annoying and I have troubles manually positioning the legend as it would not position itself at the place I would hope it does.
Any thoughts? Thomas

답변 (1개)

Kelly Kearney
Kelly Kearney 2014년 3월 19일
I don't see any changes in your above example. However, a few things to check:
  • Make sure the figure's PaperPositionMode is set to 'auto'. If not, the axes may be being resized, which could affect the legend position.
  • Try export_fig instead of print. In my opinion (and most people's) it produces better output than print, and also doesn't ever try to make any size adjustments like print does.

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by