|
From: <md...@us...> - 2008-06-24 17:35:42
|
Revision: 5659
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5659&view=rev
Author: mdboom
Date: 2008-06-24 10:35:33 -0700 (Tue, 24 Jun 2008)
Log Message:
-----------
Add "transparent" kwarg to savefig to save figure without figure or axes patches.
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/figure.py
Modified: trunk/matplotlib/lib/matplotlib/figure.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/figure.py 2008-06-24 16:32:23 UTC (rev 5658)
+++ trunk/matplotlib/lib/matplotlib/figure.py 2008-06-24 17:35:33 UTC (rev 5659)
@@ -972,7 +972,8 @@
call signature::
savefig(fname, dpi=None, facecolor='w', edgecolor='w',
- orientation='portrait', papertype=None, format=None):
+ orientation='portrait', papertype=None, format=None,
+ transparent=False):
Save the current figure.
@@ -1006,14 +1007,36 @@
*format*:
One of the file extensions supported by the active
backend. Most backends support png, pdf, ps, eps and svg.
+
+ *transparent*:
+ If *True*, the figure patch and axes patches will all be
+ transparent. This is useful, for example, for displaying
+ a plot on top of a colored background on a web page. The
+ transparency of these patches will be restored to their
+ original values upon exit of this function.
"""
for key in ('dpi', 'facecolor', 'edgecolor'):
if not kwargs.has_key(key):
kwargs[key] = rcParams['savefig.%s'%key]
+ transparent = kwargs.pop('transparent', False)
+ if transparent:
+ original_figure_alpha = self.figurePatch.get_alpha()
+ self.figurePatch.set_alpha(0.0)
+ original_axes_alpha = []
+ for ax in self.axes:
+ axesPatch = ax.get_frame()
+ original_axes_alpha.append(axesPatch.get_alpha())
+ axesPatch.set_alpha(0.0)
+
self.canvas.print_figure(*args, **kwargs)
+ if transparent:
+ self.figurePatch.set_alpha(original_figure_alpha)
+ for ax, alpha in zip(self.axes, original_axes_alpha):
+ ax.get_frame().set_alpha(alpha)
+
def colorbar(self, mappable, cax=None, ax=None, **kw):
if ax is None:
ax = self.gca()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|