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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Jun 1 12:28:14 PDT 2015


12 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/595e91988743/
Changeset:   595e91988743
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 02:41:33+00:00
Summary:     Add a better check for aspect ratio scaling in the scale callback
Affected #:  2 files

diff -r c12349973350b9c9b2f4c60af9a7bc6b90ea42e2 -r 595e919887433c7007d696321c1b4a878af6e24e yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -54,6 +54,7 @@
             self._type_name = "CuttingPlane"
         else:
             self._type_name = viewer._plot_type
+        self.aspect = window_plot._aspect
         self.font_properties = font_properties
         self.font_color = font_color
 

diff -r c12349973350b9c9b2f4c60af9a7bc6b90ea42e2 -r 595e919887433c7007d696321c1b4a878af6e24e yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1827,11 +1827,10 @@
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
         xsize = plot.xlim[1] - plot.xlim[0]
-        ysize = plot.ylim[1] - plot.ylim[0]
-        if xsize != ysize:
-            raise RuntimeError("Scale callback only works for plots with "
-                               "axis ratios of 1. Here: xsize = %s, ysize "
-                               " = %s." % (xsize, ysize))
+        if plot.aspect != 1.0:
+            raise NotImplementedError(
+                "Scale callback has only been implemented for plots with no "
+                "aspect ratio scaling. (aspect = {%s})".format(plot._aspect))
 
         # Setting pos overrides corner argument
         if self.pos is None:


https://bitbucket.org/yt_analysis/yt/commits/0c603c85786d/
Changeset:   0c603c85786d
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 04:22:42+00:00
Summary:     Use AnchoredSizeBar in implementation of ScaleCallback
Affected #:  1 file

diff -r 595e919887433c7007d696321c1b4a878af6e24e -r 0c603c85786d26a805caa22fef2895b0dc787ee2 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -23,6 +23,7 @@
 
 from matplotlib.patches import Circle
 from matplotlib.colors import colorConverter
+from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
 
 from yt.funcs import *
 from yt.extern.six import add_metaclass
@@ -1731,42 +1732,42 @@
 
     Annotates the scale of the plot at a specified location in the image
     (either in a preset corner, or by specifying (x,y) image coordinates with
-    the pos argument.  Coeff and units (e.g. 1 Mpc or 100 kpc) refer to the 
-    distance scale you desire to show on the plot.  If no coeff and units are 
-    specified, an appropriate pair will be determined such that your scale bar 
-    is never smaller than min_frac or greater than max_frac of your plottable 
+    the pos argument.  Coeff and units (e.g. 1 Mpc or 100 kpc) refer to the
+    distance scale you desire to show on the plot.  If no coeff and units are
+    specified, an appropriate pair will be determined such that your scale bar
+    is never smaller than min_frac or greater than max_frac of your plottable
     axis length.  For additional text and plot arguments for the text and line,
     include them as dictionaries to pass to text_args and plot_args.
-    
+
     Parameters
     ----------
 
     corner : string, optional
         Corner sets up one of 4 predeterimined locations for the timestamp
         to be displayed in the image: 'upper_left', 'upper_right', 'lower_left',
-        'lower_right' (also allows None). This value will be overridden by the 
+        'lower_right' (also allows None). This value will be overridden by the
         optional 'pos' keyword.
 
     coeff : float, optional
         The coefficient of the unit defining the distance scale (e.g. 10 kpc or
-        100 Mpc) for overplotting.  If set to None along with unit keyword, 
+        100 Mpc) for overplotting.  If set to None along with unit keyword,
         coeff will be automatically determined to be a power of 10
         relative to the best-fit unit.
 
     unit : string, optional
-        unit must be a valid yt distance unit (e.g. 'm', 'km', 'AU', 'pc', 
+        unit must be a valid yt distance unit (e.g. 'm', 'km', 'AU', 'pc',
         'kpc', etc.) or set to None.  If set to None, will be automatically
         determined to be the best-fit to the data.
 
     pos : 2- or 3-element tuples, lists, or arrays, optional
-        The image location of the timestamp in the coord system defined by the
-        coord_system kwarg.  Setting pos overrides the corner parameter.
+        The image location of the timestamp in the plot coordinate system.
+        Setting pos overrides the corner parameter.
 
     min_frac, max_frac: float, optional
-        The minimum/maximum fraction of the axis width for the scale bar to 
+        The minimum/maximum fraction of the axis width for the scale bar to
         extend. A value of 1 would allow the scale bar to extend across the
-        entire axis width.  Only used for automatically calculating 
-        best-fit coeff and unit when neither is specified, otherwise 
+        entire axis width.  Only used for automatically calculating
+        best-fit coeff and unit when neither is specified, otherwise
         disregarded.
 
     coord_system : string, optional
@@ -1783,17 +1784,14 @@
             "figure" -- the MPL figure coordinates: (0,0) is lower left, (1,1)
                         is upper right
 
-    text_args : dictionary, optional
-        A dictionary of any arbitrary parameters to be passed to the Matplotlib
-        text object.  Defaults: {'color':'white', 
-        'horizontalalignment':'center', 'verticalalignment':'top'}.
+    size_bar_args : dictionary, optional
+        A dictionary of parameters to be passed to the Matplotlib
+        AnchoredSizeBar initializer.
+        Defaults: {'pad': 0.75, 'sep': 5, 'borderpad': 0.5, 'color': 'w'}
 
-    plot_args : dictionary, optional
-        A dictionary of any arbitrary parameters to be passed to the Matplotlib
-        line object.  Defaults: {'color':'white', 'linewidth':3}.
 
     Example
-    ------- 
+    -------
 
     >>> import yt
     >>> ds = yt.load('Enzo_64/DD0020/data0020')
@@ -1803,10 +1801,12 @@
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None, 
                  max_frac=0.20, min_frac=0.018, coord_system='axis',
-                 text_args=None, plot_args=None):
+                 size_bar_args=None, draw_inset_box=False):
 
-        def_text_args = {'color':'white'}
-        def_plot_args = {'color':'white', 'linewidth':3}
+        def_size_bar_args = {'pad': 0.75,
+                             'sep': 5,
+                             'borderpad': 0.5,
+                             'color': 'w'}
 
         # Set position based on corner argument.
         self.corner = corner
@@ -1816,13 +1816,11 @@
         self.max_frac = max_frac
         self.min_frac = min_frac
         self.coord_system = coord_system
-        if text_args is None: text_args = def_text_args
-        self.text_args = text_args
-        # This assures the line and the text are aligned
-        self.text_args['horizontalalignment'] = 'center'
-        self.text_args['verticalalignment'] = 'top'
-        if plot_args is None: plot_args = def_plot_args
-        self.plot_args = plot_args
+        if size_bar_args is None:
+            self.size_bar_args = def_size_bar_args
+        else:
+            self.size_bar_args = size_bar_args
+        self.draw_inset_box = draw_inset_box
 
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
@@ -1835,23 +1833,25 @@
         # Setting pos overrides corner argument
         if self.pos is None:
             if self.corner == 'upper_left':
-                self.pos = (0.12, 0.971)
+                loc = 2
             elif self.corner == 'upper_right':
-                self.pos = (0.88, 0.971)
+                loc = 1
             elif self.corner == 'lower_left':
-                self.pos = (0.12, 0.062)
+                loc = 3
             elif self.corner == 'lower_right':
-                self.pos = (0.88, 0.062)
+                loc = 4
             elif self.corner is None:
-                self.pos = (0.5, 0.5)
+                loc = 10
             else:
                 raise SyntaxError("Argument 'corner' must be set to " 
                                   "'upper_left', 'upper_right', 'lower_left', " 
                                   "'lower_right', or None")
+        else:
+            loc = self.pos
 
         # When identifying a best fit distance unit, do not allow scale marker
-        # to be greater than max_frac fraction of xaxis or under min_frac 
-        # fraction of xaxis 
+        # to be greater than max_frac fraction of xaxis or under min_frac
+        # fraction of xaxis
         max_scale = self.max_frac * xsize
         min_scale = self.min_frac * xsize
 
@@ -1860,30 +1860,32 @@
 
         # If no units are set, then identify a best fit distance unit
         if self.unit is None:
-            min_scale = plot.ds.get_smallest_appropriate_unit(min_scale, 
-                                                   return_quantity=True)
-            max_scale = plot.ds.get_smallest_appropriate_unit(max_scale, 
-                                                   return_quantity=True)
+            min_scale = plot.ds.get_smallest_appropriate_unit(
+                min_scale, return_quantity=True)
+            max_scale = plot.ds.get_smallest_appropriate_unit(
+                max_scale, return_quantity=True)
             self.coeff = max_scale.v
             self.unit = max_scale.units
         self.scale = YTQuantity(self.coeff, self.unit)
-        self.text = "{scale} {units}".format(scale=int(self.coeff), 
-                                             units=self.unit)
-        image_scale = (plot.frb.convert_distance_x(self.scale) / \
-                       plot.frb.convert_distance_x(xsize)).v
+        text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
+        image_scale = (plot.frb.convert_distance_x(self.scale) /
+                       plot.frb.convert_distance_x(xsize)).v*xsize.v
 
-        # This is just a fancy wrapper around the TextLabelCallback and the
-        # ImageLineCallback
-        pos_line_start = (self.pos[0]-image_scale/2, self.pos[1]+0.01)
-        pos_line_end = (self.pos[0]+image_scale/2, self.pos[1]+0.01)
-        icb = LinePlotCallback(pos_line_start, pos_line_end, 
-                               coord_system=self.coord_system, 
-                               plot_args=self.plot_args)
-        icb(plot)
-        tcb = TextLabelCallback(self.pos, self.text, 
-                                coord_system=self.coord_system,
-                                text_args=self.text_args)
-        return tcb(plot)
+        if 'size_vertical' not in size_bar_args:
+            size_bar_args['size_vertical'] = image_scale/20
+
+        if 'fontproperties' not in size_bar_args:
+            size_bar_args['fontproperties'] = plot.font_properties
+
+        if 'frameon' not in size_bar_args:
+            size_bar_args['frameon'] = self.draw_inset_box
+
+        bar = AnchoredSizeBar(plot._axes.transData, image_scale, text, loc,
+                              **size_bar_args)
+
+        plot._axes.add_artist(bar)
+
+        return plot
 
 class RayCallback(PlotCallback):
     """


https://bitbucket.org/yt_analysis/yt/commits/b16210127138/
Changeset:   b16210127138
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 04:33:31+00:00
Summary:     Fix undefined local variable error
Affected #:  1 file

diff -r 0c603c85786d26a805caa22fef2895b0dc787ee2 -r b1621012713898f90d47337ed5352e135558133e yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1871,17 +1871,17 @@
         image_scale = (plot.frb.convert_distance_x(self.scale) /
                        plot.frb.convert_distance_x(xsize)).v*xsize.v
 
-        if 'size_vertical' not in size_bar_args:
-            size_bar_args['size_vertical'] = image_scale/20
+        if 'size_vertical' not in self.size_bar_args:
+            self.size_bar_args['size_vertical'] = image_scale/20
 
-        if 'fontproperties' not in size_bar_args:
-            size_bar_args['fontproperties'] = plot.font_properties
+        if 'fontproperties' not in self.size_bar_args:
+            self.size_bar_args['fontproperties'] = plot.font_properties
 
-        if 'frameon' not in size_bar_args:
-            size_bar_args['frameon'] = self.draw_inset_box
+        if 'frameon' not in self.size_bar_args:
+            self.size_bar_args['frameon'] = self.draw_inset_box
 
         bar = AnchoredSizeBar(plot._axes.transData, image_scale, text, loc,
-                              **size_bar_args)
+                              **self.size_bar_args)
 
         plot._axes.add_artist(bar)
 


https://bitbucket.org/yt_analysis/yt/commits/0b812bc47e43/
Changeset:   0b812bc47e43
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 05:12:46+00:00
Summary:     Use axes coordinates for scale callback
Affected #:  1 file

diff -r b1621012713898f90d47337ed5352e135558133e -r 0b812bc47e435b3828c522a67445951a083a0033 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1869,10 +1869,10 @@
         self.scale = YTQuantity(self.coeff, self.unit)
         text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
         image_scale = (plot.frb.convert_distance_x(self.scale) /
-                       plot.frb.convert_distance_x(xsize)).v*xsize.v
+                       plot.frb.convert_distance_x(xsize)).v
 
         if 'size_vertical' not in self.size_bar_args:
-            self.size_bar_args['size_vertical'] = image_scale/20
+            self.size_bar_args['size_vertical'] = .01
 
         if 'fontproperties' not in self.size_bar_args:
             self.size_bar_args['fontproperties'] = plot.font_properties
@@ -1880,7 +1880,7 @@
         if 'frameon' not in self.size_bar_args:
             self.size_bar_args['frameon'] = self.draw_inset_box
 
-        bar = AnchoredSizeBar(plot._axes.transData, image_scale, text, loc,
+        bar = AnchoredSizeBar(plot._axes.transAxes, image_scale, text, loc,
                               **self.size_bar_args)
 
         plot._axes.add_artist(bar)


https://bitbucket.org/yt_analysis/yt/commits/d7c563a9dbd1/
Changeset:   d7c563a9dbd1
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 05:55:21+00:00
Summary:     Update docstrings to reflect API changes
Affected #:  1 file

diff -r 0b812bc47e435b3828c522a67445951a083a0033 -r d7c563a9dbd1521691ae2c5eefc430f0a57997a0 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1728,7 +1728,7 @@
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
                    max_frac=0.2, min_frac=0.018, coord_system='axis',
-                   text_args=None, plot_args=None)
+                   size_bar_args=None, draw_inset_box=False)
 
     Annotates the scale of the plot at a specified location in the image
     (either in a preset corner, or by specifying (x,y) image coordinates with
@@ -1736,8 +1736,9 @@
     distance scale you desire to show on the plot.  If no coeff and units are
     specified, an appropriate pair will be determined such that your scale bar
     is never smaller than min_frac or greater than max_frac of your plottable
-    axis length.  For additional text and plot arguments for the text and line,
-    include them as dictionaries to pass to text_args and plot_args.
+    axis length.  Additional customization of the scale bar is possible by
+    adjusting the size_bar_args dictionary.  This accepts keyword arguments
+    for the AnchoredSizeBar class in matplotlib's axes_grid toolkit.
 
     Parameters
     ----------


https://bitbucket.org/yt_analysis/yt/commits/9995be4c590d/
Changeset:   9995be4c590d
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 18:50:29+00:00
Summary:     Hnadle inset box properties separately from scale bar properties
Affected #:  1 file

diff -r b1621012713898f90d47337ed5352e135558133e -r 9995be4c590d4ae916d5d97d7ffd5e9e0e24a55c yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1743,7 +1743,7 @@
     ----------
 
     corner : string, optional
-        Corner sets up one of 4 predeterimined locations for the timestamp
+        Corner sets up one of 4 predeterimined locations for the scale bar
         to be displayed in the image: 'upper_left', 'upper_right', 'lower_left',
         'lower_right' (also allows None). This value will be overridden by the
         optional 'pos' keyword.
@@ -1760,7 +1760,7 @@
         determined to be the best-fit to the data.
 
     pos : 2- or 3-element tuples, lists, or arrays, optional
-        The image location of the timestamp in the plot coordinate system.
+        The image location of the scale bar in the plot coordinate system.
         Setting pos overrides the corner parameter.
 
     min_frac, max_frac: float, optional
@@ -1787,7 +1787,13 @@
     size_bar_args : dictionary, optional
         A dictionary of parameters to be passed to the Matplotlib
         AnchoredSizeBar initializer.
-        Defaults: {'pad': 0.75, 'sep': 5, 'borderpad': 0.5, 'color': 'w'}
+        Defaults: {'pad': 0.25, 'sep': 5, 'borderpad': 1, 'color': 'w'}
+
+    inset_box_args : dictionary, optional
+        A dictionary of keyword arguments to be passed to the matplotlib Patch
+        object that represents the inset box.
+        Defaults: {'facecolor': 'black', 'linewidth': 3, 'edgecolor', 'white',
+                   'alpha': 0.5, 'boxstyle': 'square'}
 
 
     Example
@@ -1801,12 +1807,22 @@
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None, 
                  max_frac=0.20, min_frac=0.018, coord_system='axis',
-                 size_bar_args=None, draw_inset_box=False):
+                 size_bar_args=None, draw_inset_box=False, inset_box_args=None):
 
-        def_size_bar_args = {'pad': 0.75,
-                             'sep': 5,
-                             'borderpad': 0.5,
-                             'color': 'w'}
+        def_size_bar_args = {
+            'pad': 0.25,
+            'sep': 5,
+            'borderpad': 1,
+            'color': 'w'
+        }
+
+        inset_box_args = {
+            'facecolor': 'black',
+            'linewidth': 3,
+            'edgecolor': 'white',
+            'alpha': 0.5,
+            'boxstyle': 'square',
+        }
 
         # Set position based on corner argument.
         self.corner = corner
@@ -1820,6 +1836,10 @@
             self.size_bar_args = def_size_bar_args
         else:
             self.size_bar_args = size_bar_args
+        if inset_box_args is None:
+            self.inset_box_args = def_inset_box_args
+        else:
+            self.inset_box_args = inset_box_args
         self.draw_inset_box = draw_inset_box
 
     def __call__(self, plot):
@@ -1871,18 +1891,19 @@
         image_scale = (plot.frb.convert_distance_x(self.scale) /
                        plot.frb.convert_distance_x(xsize)).v*xsize.v
 
-        if 'size_vertical' not in self.size_bar_args:
-            self.size_bar_args['size_vertical'] = image_scale/20
-
-        if 'fontproperties' not in self.size_bar_args:
-            self.size_bar_args['fontproperties'] = plot.font_properties
-
-        if 'frameon' not in self.size_bar_args:
-            self.size_bar_args['frameon'] = self.draw_inset_box
+        size_vertical = self.size_bar_args.pop('size_vertical', image_scale/20)
+        fontproperties = self.size_bar_args.pop(
+            'fontproperties', plot.font_properties)
+        frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
 
         bar = AnchoredSizeBar(plot._axes.transData, image_scale, text, loc,
+                              size_vertical=size_vertical,
+                              fontproperties=fontproperties,
+                              frameon=frameon,
                               **self.size_bar_args)
 
+        bar.patch.set(**self.inset_box_args)
+
         plot._axes.add_artist(bar)
 
         return plot


https://bitbucket.org/yt_analysis/yt/commits/76c976358873/
Changeset:   76c976358873
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 18:52:05+00:00
Summary:     merging
Affected #:  1 file

diff -r 9995be4c590d4ae916d5d97d7ffd5e9e0e24a55c -r 76c9763588730144d2499ec5715eb92b3e53dafc yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1728,7 +1728,7 @@
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
                    max_frac=0.2, min_frac=0.018, coord_system='axis',
-                   text_args=None, plot_args=None)
+                   size_bar_args=None, draw_inset_box=False)
 
     Annotates the scale of the plot at a specified location in the image
     (either in a preset corner, or by specifying (x,y) image coordinates with
@@ -1736,8 +1736,9 @@
     distance scale you desire to show on the plot.  If no coeff and units are
     specified, an appropriate pair will be determined such that your scale bar
     is never smaller than min_frac or greater than max_frac of your plottable
-    axis length.  For additional text and plot arguments for the text and line,
-    include them as dictionaries to pass to text_args and plot_args.
+    axis length.  Additional customization of the scale bar is possible by
+    adjusting the size_bar_args dictionary.  This accepts keyword arguments
+    for the AnchoredSizeBar class in matplotlib's axes_grid toolkit.
 
     Parameters
     ----------
@@ -1889,7 +1890,7 @@
         self.scale = YTQuantity(self.coeff, self.unit)
         text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
         image_scale = (plot.frb.convert_distance_x(self.scale) /
-                       plot.frb.convert_distance_x(xsize)).v*xsize.v
+                       plot.frb.convert_distance_x(xsize)).v
 
         size_vertical = self.size_bar_args.pop('size_vertical', image_scale/20)
         fontproperties = self.size_bar_args.pop(


https://bitbucket.org/yt_analysis/yt/commits/01d72c4818b6/
Changeset:   01d72c4818b6
Branch:      yt
User:        ngoldbaum
Date:        2015-05-27 18:53:11+00:00
Summary:     Fixing a merge error
Affected #:  1 file

diff -r 76c9763588730144d2499ec5715eb92b3e53dafc -r 01d72c4818b60a2d365d22047b50d2e2011b6955 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1897,7 +1897,7 @@
             'fontproperties', plot.font_properties)
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
 
-        bar = AnchoredSizeBar(plot._axes.transData, image_scale, text, loc,
+        bar = AnchoredSizeBar(plot._axes.transAxes, image_scale, text, loc,
                               size_vertical=size_vertical,
                               fontproperties=fontproperties,
                               frameon=frameon,


https://bitbucket.org/yt_analysis/yt/commits/232088f62c56/
Changeset:   232088f62c56
Branch:      yt
User:        ngoldbaum
Date:        2015-05-28 00:52:01+00:00
Summary:     Use absolute positioning for the scale bar
Affected #:  1 file

diff -r 01d72c4818b60a2d365d22047b50d2e2011b6955 -r 232088f62c56f94215ba437f44e51ae34b661330 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1854,21 +1854,19 @@
         # Setting pos overrides corner argument
         if self.pos is None:
             if self.corner == 'upper_left':
-                loc = 2
+                self.pos = (0.135, 0.945)
             elif self.corner == 'upper_right':
-                loc = 1
+                self.pos = (0.86, 0.945)
             elif self.corner == 'lower_left':
-                loc = 3
+                self.pos = (0.135, 0.062)
             elif self.corner == 'lower_right':
-                loc = 4
+                self.pos = (0.86, 0.062)
             elif self.corner is None:
-                loc = 10
+                self.pos = (0.5, 0.5)
             else:
                 raise SyntaxError("Argument 'corner' must be set to " 
                                   "'upper_left', 'upper_right', 'lower_left', " 
                                   "'lower_right', or None")
-        else:
-            loc = self.pos
 
         # When identifying a best fit distance unit, do not allow scale marker
         # to be greater than max_frac fraction of xaxis or under min_frac
@@ -1892,12 +1890,17 @@
         image_scale = (plot.frb.convert_distance_x(self.scale) /
                        plot.frb.convert_distance_x(xsize)).v
 
-        size_vertical = self.size_bar_args.pop('size_vertical', image_scale/20)
+        size_vertical = self.size_bar_args.pop('size_vertical', .01)
         fontproperties = self.size_bar_args.pop(
             'fontproperties', plot.font_properties)
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
 
-        bar = AnchoredSizeBar(plot._axes.transAxes, image_scale, text, loc,
+        # this "anchors" the size bar to a box centered on self.pos in axis
+        # coordinates
+        self.size_bar_args['bbox_to_anchor'] = self.pos
+        self.size_bar_args['bbox_transform'] = plot._axes.transAxes
+
+        bar = AnchoredSizeBar(plot._axes.transAxes, image_scale, text, 10,
                               size_vertical=size_vertical,
                               fontproperties=fontproperties,
                               frameon=frameon,


https://bitbucket.org/yt_analysis/yt/commits/a9aff8863dab/
Changeset:   a9aff8863dab
Branch:      yt
User:        ngoldbaum
Date:        2015-05-28 01:06:31+00:00
Summary:     Update docstrings to include draw_inset_box
Affected #:  1 file

diff -r 232088f62c56f94215ba437f44e51ae34b661330 -r a9aff8863dab5d1c441eaf788a7b3fb50033e807 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1790,6 +1790,9 @@
         AnchoredSizeBar initializer.
         Defaults: {'pad': 0.25, 'sep': 5, 'borderpad': 1, 'color': 'w'}
 
+    draw_inset_box : boolean, optional
+        Whether or not an inset box should be included around the scale bar.
+
     inset_box_args : dictionary, optional
         A dictionary of keyword arguments to be passed to the matplotlib Patch
         object that represents the inset box.


https://bitbucket.org/yt_analysis/yt/commits/8844192c89d9/
Changeset:   8844192c89d9
Branch:      yt
User:        chummels
Date:        2015-05-29 21:53:55+00:00
Summary:     Recentering the scale and timestamp callback positions to align; updating docstring.
Affected #:  1 file

diff -r a9aff8863dab5d1c441eaf788a7b3fb50033e807 -r 8844192c89d902deffe1d3f3e351cf131a63580e yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1666,11 +1666,11 @@
         # Setting pos overrides corner argument
         if self.pos[0] is None or self.pos[1] is None:
             if self.corner == 'upper_left':
-                self.pos = (0.03, 0.97)
+                self.pos = (0.03, 0.96)
                 self.text_args['horizontalalignment'] = 'left'
                 self.text_args['verticalalignment'] = 'top'
             elif self.corner == 'upper_right':
-                self.pos = (0.97, 0.97)
+                self.pos = (0.97, 0.96)
                 self.text_args['horizontalalignment'] = 'right'
                 self.text_args['verticalalignment'] = 'top'
             elif self.corner == 'lower_left':
@@ -1727,8 +1727,9 @@
 class ScaleCallback(PlotCallback):
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
-                   max_frac=0.2, min_frac=0.018, coord_system='axis',
-                   size_bar_args=None, draw_inset_box=False)
+                   max_frac=0.16, min_frac=0.015, coord_system='axis',
+                   size_bar_args=None, draw_inset_box=False, 
+                   inset_box_args=None)
 
     Annotates the scale of the plot at a specified location in the image
     (either in a preset corner, or by specifying (x,y) image coordinates with
@@ -1810,11 +1811,11 @@
     """
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None, 
-                 max_frac=0.20, min_frac=0.018, coord_system='axis',
+                 max_frac=0.16, min_frac=0.015, coord_system='axis',
                  size_bar_args=None, draw_inset_box=False, inset_box_args=None):
 
         def_size_bar_args = {
-            'pad': 0.25,
+            'pad': 0.05,
             'sep': 5,
             'borderpad': 1,
             'color': 'w'
@@ -1857,13 +1858,13 @@
         # Setting pos overrides corner argument
         if self.pos is None:
             if self.corner == 'upper_left':
-                self.pos = (0.135, 0.945)
+                self.pos = (0.11, 0.952)
             elif self.corner == 'upper_right':
-                self.pos = (0.86, 0.945)
+                self.pos = (0.89, 0.952)
             elif self.corner == 'lower_left':
-                self.pos = (0.135, 0.062)
+                self.pos = (0.11, 0.052)
             elif self.corner == 'lower_right':
-                self.pos = (0.86, 0.062)
+                self.pos = (0.89, 0.052)
             elif self.corner is None:
                 self.pos = (0.5, 0.5)
             else:
@@ -1893,7 +1894,7 @@
         image_scale = (plot.frb.convert_distance_x(self.scale) /
                        plot.frb.convert_distance_x(xsize)).v
 
-        size_vertical = self.size_bar_args.pop('size_vertical', .01)
+        size_vertical = self.size_bar_args.pop('size_vertical', .005)
         fontproperties = self.size_bar_args.pop(
             'fontproperties', plot.font_properties)
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)


https://bitbucket.org/yt_analysis/yt/commits/4da925e20253/
Changeset:   4da925e20253
Branch:      yt
User:        MatthewTurk
Date:        2015-06-01 19:28:03+00:00
Summary:     Merged in ngoldbaum/yt (pull request #1600)

annotate_scale improvements
Affected #:  2 files

diff -r ac0abcc06c420713e8e4dba44178a0c5e3854267 -r 4da925e2025330de13160f8cf4ad20fb44932023 yt/visualization/base_plot_types.py
--- a/yt/visualization/base_plot_types.py
+++ b/yt/visualization/base_plot_types.py
@@ -54,6 +54,7 @@
             self._type_name = "CuttingPlane"
         else:
             self._type_name = viewer._plot_type
+        self.aspect = window_plot._aspect
         self.font_properties = font_properties
         self.font_color = font_color
 

diff -r ac0abcc06c420713e8e4dba44178a0c5e3854267 -r 4da925e2025330de13160f8cf4ad20fb44932023 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -23,6 +23,7 @@
 
 from matplotlib.patches import Circle
 from matplotlib.colors import colorConverter
+from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
 
 from yt.funcs import *
 from yt.extern.six import add_metaclass
@@ -1665,11 +1666,11 @@
         # Setting pos overrides corner argument
         if self.pos[0] is None or self.pos[1] is None:
             if self.corner == 'upper_left':
-                self.pos = (0.03, 0.97)
+                self.pos = (0.03, 0.96)
                 self.text_args['horizontalalignment'] = 'left'
                 self.text_args['verticalalignment'] = 'top'
             elif self.corner == 'upper_right':
-                self.pos = (0.97, 0.97)
+                self.pos = (0.97, 0.96)
                 self.text_args['horizontalalignment'] = 'right'
                 self.text_args['verticalalignment'] = 'top'
             elif self.corner == 'lower_left':
@@ -1726,47 +1727,49 @@
 class ScaleCallback(PlotCallback):
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
-                   max_frac=0.2, min_frac=0.018, coord_system='axis',
-                   text_args=None, plot_args=None)
+                   max_frac=0.16, min_frac=0.015, coord_system='axis',
+                   size_bar_args=None, draw_inset_box=False, 
+                   inset_box_args=None)
 
     Annotates the scale of the plot at a specified location in the image
     (either in a preset corner, or by specifying (x,y) image coordinates with
-    the pos argument.  Coeff and units (e.g. 1 Mpc or 100 kpc) refer to the 
-    distance scale you desire to show on the plot.  If no coeff and units are 
-    specified, an appropriate pair will be determined such that your scale bar 
-    is never smaller than min_frac or greater than max_frac of your plottable 
-    axis length.  For additional text and plot arguments for the text and line,
-    include them as dictionaries to pass to text_args and plot_args.
-    
+    the pos argument.  Coeff and units (e.g. 1 Mpc or 100 kpc) refer to the
+    distance scale you desire to show on the plot.  If no coeff and units are
+    specified, an appropriate pair will be determined such that your scale bar
+    is never smaller than min_frac or greater than max_frac of your plottable
+    axis length.  Additional customization of the scale bar is possible by
+    adjusting the size_bar_args dictionary.  This accepts keyword arguments
+    for the AnchoredSizeBar class in matplotlib's axes_grid toolkit.
+
     Parameters
     ----------
 
     corner : string, optional
-        Corner sets up one of 4 predeterimined locations for the timestamp
+        Corner sets up one of 4 predeterimined locations for the scale bar
         to be displayed in the image: 'upper_left', 'upper_right', 'lower_left',
-        'lower_right' (also allows None). This value will be overridden by the 
+        'lower_right' (also allows None). This value will be overridden by the
         optional 'pos' keyword.
 
     coeff : float, optional
         The coefficient of the unit defining the distance scale (e.g. 10 kpc or
-        100 Mpc) for overplotting.  If set to None along with unit keyword, 
+        100 Mpc) for overplotting.  If set to None along with unit keyword,
         coeff will be automatically determined to be a power of 10
         relative to the best-fit unit.
 
     unit : string, optional
-        unit must be a valid yt distance unit (e.g. 'm', 'km', 'AU', 'pc', 
+        unit must be a valid yt distance unit (e.g. 'm', 'km', 'AU', 'pc',
         'kpc', etc.) or set to None.  If set to None, will be automatically
         determined to be the best-fit to the data.
 
     pos : 2- or 3-element tuples, lists, or arrays, optional
-        The image location of the timestamp in the coord system defined by the
-        coord_system kwarg.  Setting pos overrides the corner parameter.
+        The image location of the scale bar in the plot coordinate system.
+        Setting pos overrides the corner parameter.
 
     min_frac, max_frac: float, optional
-        The minimum/maximum fraction of the axis width for the scale bar to 
+        The minimum/maximum fraction of the axis width for the scale bar to
         extend. A value of 1 would allow the scale bar to extend across the
-        entire axis width.  Only used for automatically calculating 
-        best-fit coeff and unit when neither is specified, otherwise 
+        entire axis width.  Only used for automatically calculating
+        best-fit coeff and unit when neither is specified, otherwise
         disregarded.
 
     coord_system : string, optional
@@ -1783,17 +1786,23 @@
             "figure" -- the MPL figure coordinates: (0,0) is lower left, (1,1)
                         is upper right
 
-    text_args : dictionary, optional
-        A dictionary of any arbitrary parameters to be passed to the Matplotlib
-        text object.  Defaults: {'color':'white', 
-        'horizontalalignment':'center', 'verticalalignment':'top'}.
+    size_bar_args : dictionary, optional
+        A dictionary of parameters to be passed to the Matplotlib
+        AnchoredSizeBar initializer.
+        Defaults: {'pad': 0.25, 'sep': 5, 'borderpad': 1, 'color': 'w'}
 
-    plot_args : dictionary, optional
-        A dictionary of any arbitrary parameters to be passed to the Matplotlib
-        line object.  Defaults: {'color':'white', 'linewidth':3}.
+    draw_inset_box : boolean, optional
+        Whether or not an inset box should be included around the scale bar.
+
+    inset_box_args : dictionary, optional
+        A dictionary of keyword arguments to be passed to the matplotlib Patch
+        object that represents the inset box.
+        Defaults: {'facecolor': 'black', 'linewidth': 3, 'edgecolor', 'white',
+                   'alpha': 0.5, 'boxstyle': 'square'}
+
 
     Example
-    ------- 
+    -------
 
     >>> import yt
     >>> ds = yt.load('Enzo_64/DD0020/data0020')
@@ -1802,11 +1811,23 @@
     """
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None, 
-                 max_frac=0.20, min_frac=0.018, coord_system='axis',
-                 text_args=None, plot_args=None):
+                 max_frac=0.16, min_frac=0.015, coord_system='axis',
+                 size_bar_args=None, draw_inset_box=False, inset_box_args=None):
 
-        def_text_args = {'color':'white'}
-        def_plot_args = {'color':'white', 'linewidth':3}
+        def_size_bar_args = {
+            'pad': 0.05,
+            'sep': 5,
+            'borderpad': 1,
+            'color': 'w'
+        }
+
+        inset_box_args = {
+            'facecolor': 'black',
+            'linewidth': 3,
+            'edgecolor': 'white',
+            'alpha': 0.5,
+            'boxstyle': 'square',
+        }
 
         # Set position based on corner argument.
         self.corner = corner
@@ -1816,33 +1837,34 @@
         self.max_frac = max_frac
         self.min_frac = min_frac
         self.coord_system = coord_system
-        if text_args is None: text_args = def_text_args
-        self.text_args = text_args
-        # This assures the line and the text are aligned
-        self.text_args['horizontalalignment'] = 'center'
-        self.text_args['verticalalignment'] = 'top'
-        if plot_args is None: plot_args = def_plot_args
-        self.plot_args = plot_args
+        if size_bar_args is None:
+            self.size_bar_args = def_size_bar_args
+        else:
+            self.size_bar_args = size_bar_args
+        if inset_box_args is None:
+            self.inset_box_args = def_inset_box_args
+        else:
+            self.inset_box_args = inset_box_args
+        self.draw_inset_box = draw_inset_box
 
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
         xsize = plot.xlim[1] - plot.xlim[0]
-        ysize = plot.ylim[1] - plot.ylim[0]
-        if xsize != ysize:
-            raise RuntimeError("Scale callback only works for plots with "
-                               "axis ratios of 1. Here: xsize = %s, ysize "
-                               " = %s." % (xsize, ysize))
+        if plot.aspect != 1.0:
+            raise NotImplementedError(
+                "Scale callback has only been implemented for plots with no "
+                "aspect ratio scaling. (aspect = {%s})".format(plot._aspect))
 
         # Setting pos overrides corner argument
         if self.pos is None:
             if self.corner == 'upper_left':
-                self.pos = (0.12, 0.971)
+                self.pos = (0.11, 0.952)
             elif self.corner == 'upper_right':
-                self.pos = (0.88, 0.971)
+                self.pos = (0.89, 0.952)
             elif self.corner == 'lower_left':
-                self.pos = (0.12, 0.062)
+                self.pos = (0.11, 0.052)
             elif self.corner == 'lower_right':
-                self.pos = (0.88, 0.062)
+                self.pos = (0.89, 0.052)
             elif self.corner is None:
                 self.pos = (0.5, 0.5)
             else:
@@ -1851,8 +1873,8 @@
                                   "'lower_right', or None")
 
         # When identifying a best fit distance unit, do not allow scale marker
-        # to be greater than max_frac fraction of xaxis or under min_frac 
-        # fraction of xaxis 
+        # to be greater than max_frac fraction of xaxis or under min_frac
+        # fraction of xaxis
         max_scale = self.max_frac * xsize
         min_scale = self.min_frac * xsize
 
@@ -1861,30 +1883,38 @@
 
         # If no units are set, then identify a best fit distance unit
         if self.unit is None:
-            min_scale = plot.ds.get_smallest_appropriate_unit(min_scale, 
-                                                   return_quantity=True)
-            max_scale = plot.ds.get_smallest_appropriate_unit(max_scale, 
-                                                   return_quantity=True)
+            min_scale = plot.ds.get_smallest_appropriate_unit(
+                min_scale, return_quantity=True)
+            max_scale = plot.ds.get_smallest_appropriate_unit(
+                max_scale, return_quantity=True)
             self.coeff = max_scale.v
             self.unit = max_scale.units
         self.scale = YTQuantity(self.coeff, self.unit)
-        self.text = "{scale} {units}".format(scale=int(self.coeff), 
-                                             units=self.unit)
-        image_scale = (plot.frb.convert_distance_x(self.scale) / \
+        text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
+        image_scale = (plot.frb.convert_distance_x(self.scale) /
                        plot.frb.convert_distance_x(xsize)).v
 
-        # This is just a fancy wrapper around the TextLabelCallback and the
-        # ImageLineCallback
-        pos_line_start = (self.pos[0]-image_scale/2, self.pos[1]+0.01)
-        pos_line_end = (self.pos[0]+image_scale/2, self.pos[1]+0.01)
-        icb = LinePlotCallback(pos_line_start, pos_line_end, 
-                               coord_system=self.coord_system, 
-                               plot_args=self.plot_args)
-        icb(plot)
-        tcb = TextLabelCallback(self.pos, self.text, 
-                                coord_system=self.coord_system,
-                                text_args=self.text_args)
-        return tcb(plot)
+        size_vertical = self.size_bar_args.pop('size_vertical', .005)
+        fontproperties = self.size_bar_args.pop(
+            'fontproperties', plot.font_properties)
+        frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
+
+        # this "anchors" the size bar to a box centered on self.pos in axis
+        # coordinates
+        self.size_bar_args['bbox_to_anchor'] = self.pos
+        self.size_bar_args['bbox_transform'] = plot._axes.transAxes
+
+        bar = AnchoredSizeBar(plot._axes.transAxes, image_scale, text, 10,
+                              size_vertical=size_vertical,
+                              fontproperties=fontproperties,
+                              frameon=frameon,
+                              **self.size_bar_args)
+
+        bar.patch.set(**self.inset_box_args)
+
+        plot._axes.add_artist(bar)
+
+        return plot
 
 class RayCallback(PlotCallback):
     """

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