MATLAB: Does legend text appear outside the legend box when I use the PRINT function to save a figure as a JPEG-file in MATLAB 7.0 (R14)

exportfiguregraphicsguihandlejpeglegendMATLABposition;printresizetext;

When I export figures containing a legend to a jpeg file, the text in the legend appears outside the legend box. For example, if I execute the following code:
plot(1:10)
set (gca, 'position', [0.13 0.12 0.775 0.805])
set (gcf, 'paperposition', [1 2 4 3])
l = legend ('Plot');
print -djpeg legend.jpg
The text "Plot 1" appears outside the legend box in the jpeg. This problem does not occur in MATLAB 6.5.1 (R13SP1) and earlier.

Best Answer

We have verified that there is a bug in MATLAB 7.0 (R14) in the way that the PRINT function resizes the legend when the PaperPositionMode property of a figure is set to 'manual' instead of 'auto'. The PaperPositionMode property defaults to 'auto', but is set to 'manual' when you issue a SET command to change the PaperPosition property of a figure. To workaround the issue, avoid using the 'PaperPosition' property to control the size of the figure in the JPEG. Instead:
1. Draw the figure and the legend.
2. Resize the window to the size you want the figure to be when it's saved as a JPEG by using the Position property.
3. Use the PRINT command to create the JPEG.
4. Resize the window back.
You can learn more about all properties of a figure, including PaperPostion and PaperPositionMode, at the following URL: