MATLAB: Visualization of the legend outside of the image

figurelegend

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.

Best Answer

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