|
6 | 6 |
|
7 | 7 | .. contents:: |
8 | 8 |
|
| 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 | + |
9 | 37 |
|
10 | 38 | .. _howto-subplots-adjust: |
11 | 39 |
|
|
0 commit comments