Search code examples
matlabplotbordermatlab-figure

How can I create a border around the edge of a MATLAB figure window?


I'd like to put a border around a figure before saving my plots to .png for highlighting some plots that are most important. Is there any way to draw a rectangle outside of the axes plot region?

I'd like the border to extend around the entire plot even including the plot title and axes labels.


Solution

  • Found the solution. After saving a plot to an image, you can reload it into a figure and then draw a border on top of the image.

    img = imread('test_image.png');
    fh = figure;
    imshow(img,'border','tight')
    hold on;
    figurepos = get(gcf,'Position');
    rectangle('Position',[4 4 figurepos(3)-7 figurepos(4)-7],'LineWidth',5,'EdgeColor','red')