[yt-svn] commit/yt: ngoldbaum: Updating write_projection to no longer use pylab. Tweaking a bit.

Bitbucket commits-noreply at bitbucket.org
Sat Jul 28 14:17:03 PDT 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/cbf6b6340c65/
changeset:   cbf6b6340c65
branch:      yt
user:        ngoldbaum
date:        2012-07-28 23:16:50
summary:     Updating write_projection to no longer use pylab.  Tweaking a bit.
affected #:  1 file

diff -r 3c812c4399229f64217b19c9f6d68ee632316238 -r cbf6b6340c6517b77fc194da1a49d75b97fbb381 yt/visualization/image_writer.py
--- a/yt/visualization/image_writer.py
+++ b/yt/visualization/image_writer.py
@@ -332,7 +332,8 @@
     return im
 
 def write_projection(data, filename, colorbar=True, colorbar_label=None, 
-                    title=None, limits=None, take_log=True, var_fig_size=False):
+                     title=None, limits=None, take_log=True, var_fig_size=False,
+                     cmap='algae'):
     r"""Write a projection or volume rendering to disk with a variety of 
     pretty parameters such as limits, title, colorbar, etc.  write_projection
     uses the standard matplotlib interface to create the figure.  N.B. This code
@@ -362,6 +363,8 @@
     var_fig_size : boolean
         If we want the resolution (and size) of the output image to scale 
         with the resolution of the image array.  
+    cmap : string
+        The name of the colormap.
 
     Examples
     --------
@@ -372,24 +375,25 @@
                          title="Offaxis Projection", limits=(1e-3,1e-5), 
                          take_log=True)
     """
-    import pylab as pl
+    import matplotlib
+    from ._mpl_imports import *
 
     # If this is rendered as log, then apply now.
     if take_log:
-        data = na.log10(data)
-        if limits is not None:
-            limits = na.log10(limits)
-
+        norm = matplotlib.colors.LogNorm()
+    else:
+        norm = matplotlib.colors.Normalize()
+    
+    if limits is None:
+        limits = [None, None]
 
     # Create the figure and paint the data on
-    fig = pl.figure()
+    fig = matplotlib.figure.Figure()
     ax = fig.add_subplot(111)
+    fig.tight_layout()
 
-    if limits is not None:
-        cax = ax.imshow(data, vmin=limits[0], vmax=limits[1])
-    else:
-        cax = ax.imshow(data)
-
+    cax = ax.imshow(data, vmin=limits[0], vmax=limits[1], norm=norm, cmap=cmap)
+    
     if title:
         ax.set_title(title)
 
@@ -405,15 +409,32 @@
 
     # If we want the resolution of the image to scale with the resolution
     # of the image array. we increase the dpi value accordingly
+    
     if var_fig_size:
         N = data.shape[0]
         mag_factor = N/480.
-        pl.savefig(filename, dpi=100*mag_factor)
+        dpi = 100*mag_factor
     else:
-        pl.savefig(filename)
+        dpi = None
 
-    pl.clf()
-    pl.close()
+    if filename[-4:] == '.png':
+        suffix = ''
+    else:
+        suffix = '.png'
+        filename = "%s%s" % (filename, suffix)
+    mylog.info("Saving plot %s", fn)
+    if suffix == ".png":
+        canvas = FigureCanvasAgg(fig)
+    elif suffix == ".pdf":
+        canvas = FigureCanvasPdf(fig)
+    elif suffix in (".eps", ".ps"):
+        canvas = FigureCanvasPS
+    else:
+        mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
+        canvas = FigureCanvasAgg(fig)
+    canvas.print_figure(filename)
+    return filename
+
 
 def write_fits(image, filename_prefix, clobber=True, coords=None, gzip_file=False) :

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list