Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c371027

Browse files
committed
added transparent figure faq
svn path=/trunk/matplotlib/; revision=5672
1 parent 3a87bd0 commit c371027

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

doc/faq/howto_faq.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@ Howto
66

77
.. contents::
88

9+
.. _howto-transparent:
10+
11+
How do I save transparent figures?
12+
==================================
13+
14+
The :meth:`~matplotlib.pyplot.savefig` command has a keyword argument
15+
*transparent* which, if True, will make the figure and axes
16+
backgrounds transparent when saving, but will not affect the displayed
17+
image on the screen. If you need finer grained control, eg you do not
18+
want full transparency or you to affect the screen displayed version
19+
as well, you can set the alpha properties directly. The figure has a
20+
:class:`matplotlib.patches.Rectangle` instance called *figurePatch*
21+
and the axes has a Rectangle instance called *axesPatch*. You can set
22+
any property on them directly (*facecolor*, *edgecolor*, *linewidth*,
23+
*linestyle*, *alpha*). Eg::
24+
25+
fig = plt.figure()
26+
fig.figurePatch.set_alpha(0.5)
27+
ax = fig.add_subplot(111)
28+
ax.axesPatch.set_alpha(0.5)
29+
30+
If you need *all* the figure elements to be transparent, there is
31+
currently no global alpha setting, but you can set the alpha channel
32+
on individual elements, eg::
33+
34+
ax.plot(x, y, alpha=0.5)
35+
ax.set_xlabel('volts', alpha=0.5)
36+
937

1038
.. _howto-subplots-adjust:
1139

0 commit comments

Comments
 (0)