Visualization of the legend outside of the image

Hi,
I am using the following code to visualize the image with legend:
currImg = imread(imagePath);
fig = figure('Visible', 'off');
imshow(currImg);
hold all;
legendHandler = legend(textLegend(:), 'Location', 'BestOutside');
set(legendHandler,'FontSize',8);
hold off;
print(fig, '-djpeg', outfilepath);
Unfortunately, in some cases I get a legend that doesn't fit in the figure (see the attached image). How can I fix it?
[update] It seems the real culprit is
print(fig, '-djpeg', outfilepath);
as imshow shows the image correctly.

 Accepted Answer

Have you tried other location options, such as 'Best'?

4 Comments

I tried northeastoutside but it doesn't work neither. So here actually I do have two constraints:
1. it should be general enough as I process thousands of images
2. it should be outside of the main frame as I don't want to occlude any content of the image with the legend
It also seems the real culprit is
print(fig, '-djpeg', outfilepath);
as imshow shows the image correctly.
I use ghexport and it seems it works now.
hgexport(fig, outfilepath, hgexport('factorystyle'), 'Format', 'jpeg');
Ok, it seems export_fig works better, thanks a lot!

Sign in to comment.

More Answers (0)

Asked:

on 5 Oct 2013

Commented:

on 10 Oct 2013

Community Treasure Hunt

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

Start Hunting!