[yt-svn] commit/yt: 4 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon Sep 3 04:48:29 PDT 2012


4 new commits in yt:


https://bitbucket.org/yt_analysis/yt/changeset/dd13ee5cec63/
changeset:   dd13ee5cec63
branch:      yt
user:        samskillman
date:        2012-08-29 23:48:59
summary:     A new way to size the plot window frames so that they keep the same final image size for a given aspect ratio.  The calculation is a bit messy, but it now avoids relying on bbox_inches=tight.
affected #:  1 file

diff -r a7570ca33e168bbf7b9a9f4f399582b38632cc0a -r dd13ee5cec63c0625fb66438ff7c73de5cc6de2c yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -685,10 +685,12 @@
 
             # This sets the size of the figure, and defaults to making one of the dimensions smaller.
             # This should protect against giant images in the case of a very large aspect ratio.
+            norm_size = 10.0
+            cbar_frac = 0.0
             if aspect > 1.0:
-                size = (10.0, 10.0/aspect)
+                size = (aspect*norm_size*(1.+cbar_frac), norm_size)
             else:
-                size = (10.0*aspect, 10.0)
+                size = (norm_size*(1.+cbar_frac), norm_size/aspect)
 
             self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], 
                                           self._colormaps[f], size, zlim)
@@ -1184,10 +1186,13 @@
     figure = None
     def __init__(self, field, size):
         self._plot_valid = True
-        self.figure = matplotlib.figure.Figure(figsize = size, frameon = True)
+        fsize, axrect, caxrect = self._get_best_layout(size)
         # Hardcoding the axis dimensions for now
-        self.axes = self.figure.add_axes((.07,.10,.8,.8))
-        self.cax = self.figure.add_axes((.87,.10,.04,.8))
+        
+        self.figure = matplotlib.figure.Figure(figsize = fsize, 
+                                               frameon = True)
+        self.axes = self.figure.add_axes(axrect)
+        self.cax = self.figure.add_axes(caxrect)
 
     def save(self, name, canvas = None):
         if name[-4:] == '.png':
@@ -1206,9 +1211,47 @@
             else:
                 mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
                 canvas = FigureCanvasAgg(self.figure)
-        canvas.print_figure(fn, bbox_inches='tight')
+        canvas.print_figure(fn)
         return fn
 
+    def _get_best_layout(self, size):
+        aspect = 1.0*size[0]/size[1]
+
+        # add room for a colorbar
+        cbar_inches = 0.7
+        newsize = [size[0] + cbar_inches, size[1]]
+        
+        # add buffers for text, and a bit of whitespace on top
+        text_buffx = 0.7/(newsize[0])
+        text_bottomy = 0.7/size[1]
+        text_topy = 0.3/size[1]
+
+        # calculate how much room the colorbar takes
+        cbar_frac = cbar_inches/newsize[0] 
+        
+        # Calculate y fraction, then use to make x fraction.
+        yfrac = 1.0-text_bottomy-text_topy
+        ysize = yfrac*size[1]
+        xsize = aspect*ysize
+        xfrac = xsize/newsize[0]
+
+        # Now make sure it all fits!
+        xbig = xfrac + text_buffx + 2.0*cbar_frac
+        ybig = yfrac + text_bottomy + text_topy
+
+        if xbig > 1:
+            xsize /= xbig
+            ysize /= xbig
+        if ybig > 1:
+            xsize /= ybig
+            ysize /= ybig
+        xfrac = xsize/newsize[0]
+        yfrac = ysize/newsize[1]
+
+        axrect = (text_buffx, text_bottomy, xfrac, yfrac )
+        caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
+        return newsize, axrect, caxrect
+
     def _repr_png_(self):
         canvas = FigureCanvasAgg(self.figure)
         f = cStringIO.StringIO()



https://bitbucket.org/yt_analysis/yt/changeset/ecb1b4c43077/
changeset:   ecb1b4c43077
branch:      yt
user:        samskillman
date:        2012-09-01 03:57:43
summary:     Attempt to give a bit more buffer on the left side, and go back to making the images only smaller than 10x10 inches, not increasing one of the lengths.  This helps keep the text sizes large enough to read.
affected #:  1 file

diff -r dd13ee5cec63c0625fb66438ff7c73de5cc6de2c -r ecb1b4c4307763f14b9762eeba604d0238900da3 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -688,9 +688,9 @@
             norm_size = 10.0
             cbar_frac = 0.0
             if aspect > 1.0:
+                size = (norm_size*(1.+cbar_frac), norm_size/aspect)
+            else:
                 size = (aspect*norm_size*(1.+cbar_frac), norm_size)
-            else:
-                size = (norm_size*(1.+cbar_frac), norm_size/aspect)
 
             self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], 
                                           self._colormaps[f], size, zlim)
@@ -1222,7 +1222,7 @@
         newsize = [size[0] + cbar_inches, size[1]]
         
         # add buffers for text, and a bit of whitespace on top
-        text_buffx = 0.7/(newsize[0])
+        text_buffx = 1.0/(newsize[0])
         text_bottomy = 0.7/size[1]
         text_topy = 0.3/size[1]
 



https://bitbucket.org/yt_analysis/yt/changeset/e12ec7dbed9b/
changeset:   e12ec7dbed9b
branch:      yt
user:        samskillman
date:        2012-09-03 13:40:48
summary:     Switching to scientific notation a bit earlier to not push values off the edge. Thanks ngoldbaum.
affected #:  1 file

diff -r ecb1b4c4307763f14b9762eeba604d0238900da3 -r e12ec7dbed9b0ca6553545c227efc5db6e9426e7 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -1273,3 +1273,5 @@
         self.image = self.axes.imshow(data, origin='lower', extent = extent,
                                       norm = norm, vmin = self.zmin, 
                                       vmax = self.zmax, cmap = cmap)
+        self.image.axes.ticklabel_format(scilimits=(-4,3))
+



https://bitbucket.org/yt_analysis/yt/changeset/3840366c0379/
changeset:   3840366c0379
branch:      yt
user:        ngoldbaum
date:        2012-09-03 13:48:28
summary:     Merged in samskillman/yt (pull request #253)
affected #:  1 file

diff -r 80ff2fb3b5eb96f600df3da184d908b6ed4d81eb -r 3840366c03796c355a7043f43f6a135f35211be3 yt/visualization/plot_window.py
--- a/yt/visualization/plot_window.py
+++ b/yt/visualization/plot_window.py
@@ -708,10 +708,12 @@
 
             # This sets the size of the figure, and defaults to making one of the dimensions smaller.
             # This should protect against giant images in the case of a very large aspect ratio.
+            norm_size = 10.0
+            cbar_frac = 0.0
             if aspect > 1.0:
-                size = (10.0, 10.0/aspect)
+                size = (norm_size*(1.+cbar_frac), norm_size/aspect)
             else:
-                size = (10.0*aspect, 10.0)
+                size = (aspect*norm_size*(1.+cbar_frac), norm_size)
 
             self.plots[f] = WindowPlotMPL(self._frb[f], extent, self._field_transform[f], 
                                           self._colormaps[f], size, zlim)
@@ -1207,10 +1209,13 @@
     figure = None
     def __init__(self, field, size):
         self._plot_valid = True
-        self.figure = matplotlib.figure.Figure(figsize = size, frameon = True)
+        fsize, axrect, caxrect = self._get_best_layout(size)
         # Hardcoding the axis dimensions for now
-        self.axes = self.figure.add_axes((.07,.10,.8,.8))
-        self.cax = self.figure.add_axes((.87,.10,.04,.8))
+        
+        self.figure = matplotlib.figure.Figure(figsize = fsize, 
+                                               frameon = True)
+        self.axes = self.figure.add_axes(axrect)
+        self.cax = self.figure.add_axes(caxrect)
 
     def save(self, name, canvas = None):
         if name[-4:] == '.png':
@@ -1229,9 +1234,47 @@
             else:
                 mylog.warning("Unknown suffix %s, defaulting to Agg", suffix)
                 canvas = FigureCanvasAgg(self.figure)
-        canvas.print_figure(fn, bbox_inches='tight')
+        canvas.print_figure(fn)
         return fn
 
+    def _get_best_layout(self, size):
+        aspect = 1.0*size[0]/size[1]
+
+        # add room for a colorbar
+        cbar_inches = 0.7
+        newsize = [size[0] + cbar_inches, size[1]]
+        
+        # add buffers for text, and a bit of whitespace on top
+        text_buffx = 1.0/(newsize[0])
+        text_bottomy = 0.7/size[1]
+        text_topy = 0.3/size[1]
+
+        # calculate how much room the colorbar takes
+        cbar_frac = cbar_inches/newsize[0] 
+        
+        # Calculate y fraction, then use to make x fraction.
+        yfrac = 1.0-text_bottomy-text_topy
+        ysize = yfrac*size[1]
+        xsize = aspect*ysize
+        xfrac = xsize/newsize[0]
+
+        # Now make sure it all fits!
+        xbig = xfrac + text_buffx + 2.0*cbar_frac
+        ybig = yfrac + text_bottomy + text_topy
+
+        if xbig > 1:
+            xsize /= xbig
+            ysize /= xbig
+        if ybig > 1:
+            xsize /= ybig
+            ysize /= ybig
+        xfrac = xsize/newsize[0]
+        yfrac = ysize/newsize[1]
+
+        axrect = (text_buffx, text_bottomy, xfrac, yfrac )
+        caxrect = (text_buffx+xfrac, text_bottomy, cbar_frac/4., yfrac )
+        return newsize, axrect, caxrect
+
     def _repr_png_(self):
         canvas = FigureCanvasAgg(self.figure)
         f = cStringIO.StringIO()
@@ -1253,3 +1296,5 @@
         self.image = self.axes.imshow(data, origin='lower', extent = extent,
                                       norm = norm, vmin = self.zmin, 
                                       vmax = self.zmax, cmap = cmap)
+        self.image.axes.ticklabel_format(scilimits=(-4,3))
+

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