Technique Exchange: Make axes in figure bigger without changing the window size

Sometimes you need to make a plot or figure bigger on screen. A quick and dirty hack to do that in many cases is to add the single line subplot ("Position", [0.01 0.01 0.99 0.99]); to the figure.

See the difference between Figure 1 and Figure 2 below. The only difference in code is the addition of the subplot function call.

xy = [randi(200, 50, 1), randi(100, 50, 1)];

figure (1);
fill (xy(:,1), xy(:,2), "b");
axis tight equal off

figure (2);
subplot ("Position", [0.01 0.01 0.99 0.99]);
fill (xy(:,1), xy(:,2), "b");
axis tight equal off


If you leave the axis on, you can see where the axes are in each of the figure windows.

Calling subplot uses that wide margin, which makes the picture bigger without affecting the figure window size.

You can change the input position of the subplot call to suit your needs.

1 Like

I haven’t tested that yet. But to avoid a lot of unnecessary overhead that subplot is doing (for a plot that only contains one single axes objects), try replacing it with axes.

1 Like

You’re right. Calling axes gives the same result as calling subplot.

Figure 1 is the base, Figure 2 is with subplot and Figure 3 is with axes.

A timing test (plotting the same thing 100 times as a fresh figure) gives the following data:

Figure 1 base :   53.35 milliseconds
Figure 2 subplot: 55.97 milliseconds
Figure 3 axes:    54.75 milliseconds