[Yt-svn] yt-commit r1630 - trunk/yt/raven

mturk at wrangler.dreamhost.com mturk at wrangler.dreamhost.com
Thu Feb 11 21:53:52 PST 2010


Author: mturk
Date: Thu Feb 11 21:53:51 2010
New Revision: 1630
URL: http://yt.enzotools.org/changeset/1630

Log:
Updating the save_book method to use matplotlib and to allow metadata to be
saved.



Modified:
   trunk/yt/raven/PlotCollection.py
   trunk/yt/raven/PlotTypes.py

Modified: trunk/yt/raven/PlotCollection.py
==============================================================================
--- trunk/yt/raven/PlotCollection.py	(original)
+++ trunk/yt/raven/PlotCollection.py	Thu Feb 11 21:53:51 2010
@@ -461,12 +461,21 @@
             del self.plots[-1]
 
     @rootonly
-    def save_book(self, filename):
-        from pyPdf import PdfFileWriter, PdfFileReader
-        outfile = PdfFileWriter()
-        fns = self.save("__temp", format="pdf")
-        concatenate_pdfs(filename, fns)
-        for fn in fns: os.unlink(fn)
+    def save_book(self, filename, info = None):
+        """
+        This will save out a single PDF, where each page is a plot object.  The
+        *info* keyword can be a dictionary composed of the keys and values
+        "Author", "Title", "Subject", "Keywords", "Creator", "Producer" ad
+        "CreationDate".  Any keywords not filled in will be blank.  The default
+        is to use the current settings in Matplotlib for filling them in.
+        """
+        from matplotlib.backends.backend_pdf import PdfPages
+        outfile = PdfPages(filename)
+        for plot in self.plots:
+            plot.save_to_pdf(outfile)
+        if info is not None:
+            outfile._file.writeObject(outfile._file.infoObject, info)
+        outfile.close()
 
 def wrap_pylab_newplot(func):
     @wraps(func)

Modified: trunk/yt/raven/PlotTypes.py
==============================================================================
--- trunk/yt/raven/PlotTypes.py	(original)
+++ trunk/yt/raven/PlotTypes.py	Thu Feb 11 21:53:51 2010
@@ -39,6 +39,12 @@
     else:
         from matplotlib.backends.backend_agg \
                 import FigureCanvasAgg as FigureCanvas
+    try:
+        from matplotlib.backends.backend_pdf \
+                import FigureCanvasPdf as FigureCanvasPDF
+        engineVals["canvas_pdf"] = FigureCanvasPDF
+    except ImportError:
+        pass
     engineVals["canvas"] = FigureCanvas
     return
 
@@ -125,6 +131,11 @@
         self["GeneratedAt"] = self.data.pf["CurrentTimeIdentifier"]
         return fn
 
+    def save_to_pdf(self, f):
+        self._redraw_image()
+        canvas = engineVals["canvas_pdf"](self._figure)
+        canvas.print_pdf(f)
+
     def _redraw_image(self):
         pass
 



More information about the yt-svn mailing list