[yt-svn] commit/yt: MatthewTurk: Merged in mzingale/yt/yt-3.0 (pull request #1007)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Sat Jul 12 07:38:14 PDT 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/d091dd64ed46/
Changeset:   d091dd64ed46
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-07-12 16:38:06
Summary:     Merged in mzingale/yt/yt-3.0 (pull request #1007)

allow us to pass label_fmt into save_annotated to override the
Affected #:  2 files

diff -r dc4dbbeec944437ffbb5861c74aec51722db2a29 -r d091dd64ed463b8feae5398375e8ab327baeb47a yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -125,13 +125,14 @@
     Examples
     --------
 
+    >>> from yt.mods import *
+    >>> import yt.visualization.volume_rendering.api as vr
+
+    >>> pf = load('DD1701') # Load a dataset
+
     >>> cam = vr.Camera(c, L, W, (N,N), transfer_function = tf, pf = pf)
     >>> image = cam.snapshot()
-
-    >>> from yt.mods import *
-    >>> import yt.visualization.volume_rendering.api as vr
     
-    >>> pf = EnzoDataset('DD1701') # Load pf
     >>> c = [0.5]*3 # Center
     >>> L = [1.0,1.0,1.0] # Viewpoint
     >>> W = np.sqrt(3) # Width
@@ -610,7 +611,7 @@
             self.transfer_function.show(ax=self._tf_figure.axes)
         self._pylab.draw()
 
-    def annotate(self, ax, enhance=True):
+    def annotate(self, ax, enhance=True, label_fmt=None):
         ax.get_xaxis().set_visible(False)
         ax.get_xaxis().set_ticks([])
         ax.get_yaxis().set_visible(False)
@@ -619,7 +620,7 @@
         label = self.pf._get_field_info(self.fields[0]).get_label()
         if self.log_fields[0]:
             label = '$\\rm{log}\\/ $' + label
-        self.transfer_function.vert_cbar(ax=cb.ax, label=label)
+        self.transfer_function.vert_cbar(ax=cb.ax, label=label, label_fmt=label_fmt)
 
     def show_mpl(self, im, enhance=True, clear_fig=True):
         if self._pylab is None:
@@ -643,10 +644,33 @@
     def draw(self):
         self._pylab.draw()
     
-    def save_annotated(self, fn, image, enhance=True, dpi=100, clear_fig=True):
+    def save_annotated(self, fn, image, enhance=True, dpi=100, clear_fig=True, 
+                       label_fmt=None):
+        """
+        Save an image with the transfer function represented as a colorbar.
+
+        Parameters
+        ----------
+        fn : str
+           The output filename
+        image : ImageArray
+           The image to annotate
+        enhance : bool, optional
+           Enhance the contrast (default: True)
+        dpi : int, optional
+           Dots per inch in the output image (default: 100)
+        clear_fig : bool, optional
+           Reset the figure (through pylab.clf()) before drawing.  Setting 
+           this to false can allow us to overlay the image onto an 
+           existing figure
+        label_fmt : str, optional
+           A format specifier (e.g., label_fmt="%.2g") to use in formatting 
+           the data values that label the transfer function colorbar. 
+        
+        """
         image = image.swapaxes(0,1) 
         ax = self.show_mpl(image, enhance=enhance, clear_fig=clear_fig)
-        self.annotate(ax.axes, enhance)
+        self.annotate(ax.axes, enhance, label_fmt=label_fmt)
         self._pylab.savefig(fn, bbox_inches='tight', facecolor='black', dpi=dpi)
         
     def save_image(self, image, fn=None, clip_ratio=None, transparent=False):

diff -r dc4dbbeec944437ffbb5861c74aec51722db2a29 -r d091dd64ed463b8feae5398375e8ab327baeb47a yt/visualization/volume_rendering/transfer_functions.py
--- a/yt/visualization/volume_rendering/transfer_functions.py
+++ b/yt/visualization/volume_rendering/transfer_functions.py
@@ -523,7 +523,7 @@
         ax.set_ylabel("Opacity")
         ax.set_xlabel("Value")
 
-    def vert_cbar(self, ax=None, label=None):
+    def vert_cbar(self, ax=None, label=None, label_fmt=None):
         r"""Display an image of the transfer function
 
         This function loads up matplotlib and displays the current transfer function.
@@ -573,11 +573,14 @@
         ax.yaxis.set_ticks(xticks)
         def x_format(x, pos):
             val = x * (self.alpha.x[-1] - self.alpha.x[0]) / (self.alpha.x.size-1) + self.alpha.x[0]
-            if abs(val) < 1.e-3 or abs(val) > 1.e4:
-                e = np.floor(np.log10(abs(val)))
-                return r"${:.2f}\times 10^{:d}$".format(val/10.0**e, int(e))
+            if label_fmt == None:
+                if abs(val) < 1.e-3 or abs(val) > 1.e4:
+                    e = np.floor(np.log10(abs(val)))
+                    return r"${:.2f}\times 10^{:d}$".format(val/10.0**e, int(e))
+                else:
+                    return "%.1g" % (val)
             else:
-                return "%.1g" % (val)
+                return label_fmt % (val)
         ax.yaxis.set_major_formatter(FuncFormatter(x_format))
 
         yticks = np.linspace(0,1,2,endpoint=True) * max_alpha

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