Quantcast
Channel: solem's vision blog
Viewing all articles
Browse latest Browse all 31

Transparent figures

$
0
0
Matplotlib (Pylab) has an interesting option in the savefig() command; the figure background can be set to be transparent. Very useful if you want to put your figures on any non-white background (e.g. presentation slides). You can also set degrees of transparency for the different figure elements using an alpha value. See the documentation for more details.

Here's an example:

from pylab import *

# plot sin(x) for some interval
x = linspace(-2*pi,2*pi,200)
plot(x,sin(x))

# plot marker for every 4th point
plot(x[::4] ,sin(x[::4] ),'r*')
title('Function sin(x) and some points plotted')

savefig('test.pdf', transparent=True)


And here's the figure on a sample presentation slide, pretty nice.

Viewing all articles
Browse latest Browse all 31

Trending Articles