Removing margins from plots

Hi all, I’d like to save a plot (to a jpg) without the white margins around it, is there a way to do that? When googling, I came across a way to do it in Matlab (How do I decrease the margins around the subplots in my figure in MATLAB? - MATLAB Answers - MATLAB Central), but Octave figures don’t seem to have the corresponding properties.

Thanks in advance!

The margin around axes objects is controlled by the “looseinset” property. By default those are [0.13 0.11 0.095 0.075] in normalized coordinates. You can decrease those numbers to obtain smaller margins, e.g.

figure ()
hax = axes ("looseinset", [0.02 0.02 0.02 0.02])  
plot (hax, 1:10)

Thank you for your swift reply. This command is indeed helpful. However, your solution does not seem to work completely. Setting

axes(“looseinset”,[0 0 0 0]);

apparently only removes the right-hand margin. The top, bottom, and left-hand margins are a little smaller but still present. For instance, saving the plot produced by

axes(“looseinset”,[0 0 0 0]);
patch([0 0 1000 1000],[0 1000 1000 0],“r”);
axis([50 600 50 300],“off”);

should yield an all-red result, but I still get those 3 white margins.

Any further suggestions? Thanks!

Apparently even when the axes is hidden, tick labels are taken into account in the layout. Removing them somewhat improves things but there are still residual margins:

figure ("color", b)
hax = axes ("looseinset", [0 0 0 0]);
patch ([0 0 1000 1000], [0 1000 1000 0], "r");
axis (hax, [50 600 50 300], "off");
set (hax, "xtick", [], "ytick", [])

image

Anyway, if you don’t want neither ticks nor margins, you just need to set the axes position to normalized [0 0 1 1] manually:

...
set (hax, "position", [0 0 1 1])
3 Likes

This worked like a charm! Thanks so much!