It turns out that an "axes" in Matlab has three properties which determine its positioning: OuterPosition, Position, and TightInset.

*OuterPosition*gives the coordinates of the entire region within the current figure belonging to the axes.

*Position*gives the region contained by the "data" region of the axes.

*TightInset*gives the distance beyond this "data" region which is used by tick marks, labels, titles, and other decorations. Here's a sample plot with the

*OuterPosition*illustrated in yellow, the

*Position*in magenta, and the

*TightInset*in red:

Notice the space between the red rectangle and the boundary of the image. Why is that there? We can eliminate it by setting

*Position*to be equal to

*OuterPosition*minus the margins given by

*TightInset*:

`set(gca, 'Position', get(gca, 'OuterPosition') - ...`

get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);

That little matrix is there because

*OuterPosition*and

*Position*are stored as

`[x_0 y_0 width height]`

whereas *TightInset*is

`[dx_left dy_bottom dx_right dy_top]`

. The results are:*Voilà!*The offending whitespace has been removed. (For some reason, however, Matlab, seeing your modification of

*Position*, takes it upon itself to compute a new, nonsensical value of

*OutsidePosition*. This seems to be harmless...)

Another annoyance is in getting your figure to be the right size. Sure, you can scale your figure, but then the fonts will be the wrong size. The easiest thing to do is to estimate the desired size of your final figure, and have Matlab generate the figure in the correct size to begin with. The trick is to force not just the

*PaperSize*but also the

*PaperPosition*. If we want a figure 6.25 inches by 7.5 inches, we would do this:

`set(gcf, 'PaperUnits', 'inches');`

set(gcf, 'PaperSize', [6.25 7.5]);

set(gcf, 'PaperPositionMode', 'manual');

set(gcf, 'PaperPosition', [0 0 6.25 7.5]);

A yet further annoying situation is this: you dutifully utilize PDF or EPS files for your figures, and yet they appear to be included as ugly, non-scalable raster graphics! I encountered this problem just today. Matlab allows you to choose between several

*renderers*, which determine just how your figures get made. Suppose you have utilized transparency in your figure, yet are asking Matlab to output a figure to PDF, which (in the version supported by Matlab) does not support transparency. What's Matlab to do? Here's what it does do: it

*takes a screenshot*, producing a bitmap, which is then wrapped in EPS or PDF. Doh!

The trick is to ask Matlab to use the "painters" renderer. It does not support transparency, but at least you're guaranteed vector graphics output:

`set(gcf, 'renderer', 'painters');`

Finally, just for the sake of completeness, you might want to actually generate your output file:

`print(gcf, '-dpdf', 'my-figure.pdf');`

print(gcf, '-dpng', 'my-figure.png');

print(gcf, '-depsc2', 'my-figure.eps');

nibotSeptember 18 2007, 03:47:15 UTC 6 years ago

nibotSeptember 18 2007, 12:31:47 UTC 6 years ago

Additionally, the "TightInset" size, expressed in "Normalized Coordinates" will change as you scale the image, since the fraction of the image taken up by labels will decrease as you increase the size of the image. Not sure of a good way around this.

shamsterSeptember 18 2007, 17:45:21 UTC 6 years ago

nibotSeptember 18 2007, 20:45:05 UTC 6 years ago

shamsterSeptember 18 2007, 20:52:03 UTC 6 years ago

I'm still looking for alternatives, but xmgrace really does work well. It even does DFT/FFT, histograms, running averages, etc. on loaded data sets. Really handy. GNUplot just makes things really pretty.

Have you used anything outside of matlab for graphics/plotting? any recommendations?

nibotSeptember 19 2007, 00:19:51 UTC 6 years ago

The plot that inspired this post is Figure 4 from this document:

http://www.ligo.caltech.edu/~tfricke/do

shamsterSeptember 19 2007, 00:41:02 UTC 6 years ago

nibotSeptember 19 2007, 01:24:54 UTC 6 years ago

yorkaveMay 21 2008, 16:58:23 UTC 5 years ago

## transparent axes/figure

Hi, very useful tips, thanks.I've also found that I want to insert Matlab figures into presentations, in particular Keynote. I don't want to the background painted white/gray or whatever color.

If you set the axis and figure background colors to 'none', then they become transparent:

`set(gca,'Color','none');`

set(gcf, 'Color', 'none');

(obviously you can be selective about this.)

PDF export

doeshonor the 'none' color, and the axes will not be filled. ("print -dpdf")EPS export does not appear to honor the 'none' color.

nibotJuly 14 2011, 21:21:36 UTC 2 years ago

http://undocumentedmatlab.com/blog/a

Silvina MontesSeptember 8 2013, 17:50:14 UTC 7 months ago