Legend - position command & printing

6 views (last 30 days)
Thomas
Thomas on 19 Mar 2014
Answered: Kelly Kearney on 19 Mar 2014
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

Answers (1)

Kelly Kearney
Kelly Kearney on 19 Mar 2014
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.

Community Treasure Hunt

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

Start Hunting!