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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Aug 21 10:55:18 PDT 2015


12 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/38723702fa29/
Changeset:   38723702fa29
Branch:      yt
User:        chummels
Date:        2015-08-18 03:11:41+00:00
Summary:     Adding text_args keyword for annotate_scale callback.
Affected #:  1 file

diff -r bc21601eb3e3d89810ca3b5e914797f934fe1ef8 -r 38723702fa2945965b53d2086ba22ff635075906 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1739,7 +1739,7 @@
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
                    max_frac=0.16, min_frac=0.015, coord_system='axis',
-                   size_bar_args=None, draw_inset_box=False,
+                   text_args=None, 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
@@ -1749,8 +1749,11 @@
     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.
+    adjusting the text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args 
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in 
+    matplotlib's axes_grid toolkit.
 
     Parameters
     ----------
@@ -1797,6 +1800,12 @@
             "figure" -- the MPL figure coordinates: (0,0) is lower left, (1,1)
                         is upper right
 
+    text_args : dictionary, optional
+        A dictionary of parameters to used to update the font_properties
+        for the text in this callback.  For any property not set, it will
+        use the defaults of the plot.  Thus one can modify the text size with:
+        text_args={'size':24}
+
     size_bar_args : dictionary, optional
         A dictionary of parameters to be passed to the Matplotlib
         AnchoredSizeBar initializer.
@@ -1823,7 +1832,8 @@
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None,
                  max_frac=0.16, min_frac=0.015, coord_system='axis',
-                 size_bar_args=None, draw_inset_box=False, inset_box_args=None):
+                 text_args=None, size_bar_args=None, draw_inset_box=False, 
+                 inset_box_args=None):
 
         def_size_bar_args = {
             'pad': 0.05,
@@ -1857,6 +1867,7 @@
         else:
             self.inset_box_args = inset_box_args
         self.draw_inset_box = draw_inset_box
+        self.text_args = text_args
 
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
@@ -1909,6 +1920,12 @@
         fontproperties = self.size_bar_args.pop(
             'fontproperties', plot.font_properties)
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
+        if self.text_args is not None:
+            # FontProperties instances use private attributes, so prepend 
+            # text_args with _
+            for key in self.text_args:
+                new_key = "_"+key
+                setattr(fontproperties, new_key, self.text_args[key])
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/f070e6eef76b/
Changeset:   f070e6eef76b
Branch:      yt
User:        chummels
Date:        2015-08-18 03:15:29+00:00
Summary:     Updating the Plot modifications docs to reflect the change in annotate_scale().
Affected #:  1 file

diff -r 38723702fa2945965b53d2086ba22ff635075906 -r f070e6eef76b8b093c508b5081ce467bf68d5925 doc/source/visualizing/callbacks.rst
--- a/doc/source/visualizing/callbacks.rst
+++ b/doc/source/visualizing/callbacks.rst
@@ -568,23 +568,27 @@
 
 Add a Physical Scale Bar
 ~~~~~~~~~~~~~~~~~~~~~~~~
-
 .. function:: annotate_scale(corner='lower_right', coeff=None, \
-                             unit=None, pos=None, max_frac=0.2, \
-                             min_frac=0.018, text_args=None, \
-                             inset_box_args=None)
+                             unit=None, pos=None, max_frac=0.16, \
+                             min_frac=0.015, coord_system='axis', \
+                             text_args=None, size_bar_args=None, \
+                             draw_inset_box=False, inset_box_args=None)
 
    (This is a proxy for
    :class:`~yt.visualization.plot_modifications.ScaleCallback`.)
 
     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) 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 text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in
+    matplotlib's axes_grid toolkit.
 
 .. python-script::
 


https://bitbucket.org/yt_analysis/yt/commits/dadce9dc9605/
Changeset:   dadce9dc9605
Branch:      yt
User:        chummels
Date:        2015-08-20 20:17:24+00:00
Summary:     Updating annotate_scale callback to handle bad attributes being passed to font_properties object.
Affected #:  1 file

diff -r f070e6eef76b8b093c508b5081ce467bf68d5925 -r dadce9dc9605af37174bc7c18b05df14c5cb1876 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1918,14 +1918,20 @@
 
         size_vertical = self.size_bar_args.pop('size_vertical', .005)
         fontproperties = self.size_bar_args.pop(
-            'fontproperties', plot.font_properties)
+            'fontproperties', plot.font_properties.copy())
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
         if self.text_args is not None:
             # FontProperties instances use private attributes, so prepend 
             # text_args with _
             for key in self.text_args:
                 new_key = "_"+key
-                setattr(fontproperties, new_key, self.text_args[key])
+                try: 
+                    getattr(fontproperties, new_key)
+                    setattr(fontproperties, new_key, self.text_args[key])
+                except AttributeError:
+                    raise AttributeError("Cannot set text_args keyword " \
+                    "to include '%s' because MPL's fontproperties object does " \
+                    "not contain attribute '%s'." % (key, key))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/7d4b96de9a45/
Changeset:   7d4b96de9a45
Branch:      yt
User:        chummels
Date:        2015-08-20 20:18:04+00:00
Summary:     Merging.
Affected #:  2 files

diff -r a13764691cbffd5903c7d3972a18bfd04c89bc7e -r 7d4b96de9a45df774e57746c63bc5193309a70f8 doc/source/visualizing/callbacks.rst
--- a/doc/source/visualizing/callbacks.rst
+++ b/doc/source/visualizing/callbacks.rst
@@ -597,23 +597,27 @@
 
 Add a Physical Scale Bar
 ~~~~~~~~~~~~~~~~~~~~~~~~
-
 .. function:: annotate_scale(corner='lower_right', coeff=None, \
-                             unit=None, pos=None, max_frac=0.2, \
-                             min_frac=0.018, text_args=None, \
-                             inset_box_args=None)
+                             unit=None, pos=None, max_frac=0.16, \
+                             min_frac=0.015, coord_system='axis', \
+                             text_args=None, size_bar_args=None, \
+                             draw_inset_box=False, inset_box_args=None)
 
    (This is a proxy for
    :class:`~yt.visualization.plot_modifications.ScaleCallback`.)
 
     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) 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 text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in
+    matplotlib's axes_grid toolkit.
 
 .. python-script::
 

diff -r a13764691cbffd5903c7d3972a18bfd04c89bc7e -r 7d4b96de9a45df774e57746c63bc5193309a70f8 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1738,7 +1738,7 @@
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
                    max_frac=0.16, min_frac=0.015, coord_system='axis',
-                   size_bar_args=None, draw_inset_box=False,
+                   text_args=None, 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
@@ -1748,8 +1748,11 @@
     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.
+    adjusting the text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args 
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in 
+    matplotlib's axes_grid toolkit.
 
     Parameters
     ----------
@@ -1796,6 +1799,12 @@
             "figure" -- the MPL figure coordinates: (0,0) is lower left, (1,1)
                         is upper right
 
+    text_args : dictionary, optional
+        A dictionary of parameters to used to update the font_properties
+        for the text in this callback.  For any property not set, it will
+        use the defaults of the plot.  Thus one can modify the text size with:
+        text_args={'size':24}
+
     size_bar_args : dictionary, optional
         A dictionary of parameters to be passed to the Matplotlib
         AnchoredSizeBar initializer.
@@ -1822,7 +1831,8 @@
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None,
                  max_frac=0.16, min_frac=0.015, coord_system='axis',
-                 size_bar_args=None, draw_inset_box=False, inset_box_args=None):
+                 text_args=None, size_bar_args=None, draw_inset_box=False, 
+                 inset_box_args=None):
 
         def_size_bar_args = {
             'pad': 0.05,
@@ -1856,6 +1866,7 @@
         else:
             self.inset_box_args = inset_box_args
         self.draw_inset_box = draw_inset_box
+        self.text_args = text_args
 
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
@@ -1906,8 +1917,20 @@
 
         size_vertical = self.size_bar_args.pop('size_vertical', .005)
         fontproperties = self.size_bar_args.pop(
-            'fontproperties', plot.font_properties)
+            'fontproperties', plot.font_properties.copy())
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
+        if self.text_args is not None:
+            # FontProperties instances use private attributes, so prepend 
+            # text_args with _
+            for key in self.text_args:
+                new_key = "_"+key
+                try: 
+                    getattr(fontproperties, new_key)
+                    setattr(fontproperties, new_key, self.text_args[key])
+                except AttributeError:
+                    raise AttributeError("Cannot set text_args keyword " \
+                    "to include '%s' because MPL's fontproperties object does " \
+                    "not contain attribute '%s'." % (key, key))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/ef71285ab857/
Changeset:   ef71285ab857
Branch:      yt
User:        chummels
Date:        2015-08-20 20:40:31+00:00
Summary:     Using MPL's public api to set fontproperties attributes.
Affected #:  1 file

diff -r 7d4b96de9a45df774e57746c63bc5193309a70f8 -r ef71285ab8574deb1a0142f366544aab90225c26 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1923,14 +1923,14 @@
             # FontProperties instances use private attributes, so prepend 
             # text_args with _
             for key in self.text_args:
-                new_key = "_"+key
+                setter_func = "set_"+key
                 try: 
-                    getattr(fontproperties, new_key)
-                    setattr(fontproperties, new_key, self.text_args[key])
+                    func = getattr(fontproperties, setter_func)
+                    func(self.text_args[key])
                 except AttributeError:
                     raise AttributeError("Cannot set text_args keyword " \
                     "to include '%s' because MPL's fontproperties object does " \
-                    "not contain attribute '%s'." % (key, key))
+                    "not contain function '%s'." % (key, setter_func))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/101bde786856/
Changeset:   101bde786856
Branch:      yt
User:        chummels
Date:        2015-08-20 20:42:22+00:00
Summary:     Making code more compact in annotate_scale callback.
Affected #:  1 file

diff -r ef71285ab8574deb1a0142f366544aab90225c26 -r 101bde78685605fe00d89ff389f6aae69f8e8933 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1925,8 +1925,7 @@
             for key in self.text_args:
                 setter_func = "set_"+key
                 try: 
-                    func = getattr(fontproperties, setter_func)
-                    func(self.text_args[key])
+                    getattr(fontproperties, setter_func)(self.text_args[key])
                 except AttributeError:
                     raise AttributeError("Cannot set text_args keyword " \
                     "to include '%s' because MPL's fontproperties object does " \


https://bitbucket.org/yt_analysis/yt/commits/5caf5a831e6f/
Changeset:   5caf5a831e6f
Branch:      yt
User:        chummels
Date:        2015-08-20 21:44:46+00:00
Summary:     Simplifying annotate_scale() to accommodate suggestions from PR.
Affected #:  1 file

diff -r 101bde78685605fe00d89ff389f6aae69f8e8933 -r 5caf5a831e6f9b389fa1a268ab2c27830da6f525 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1866,6 +1866,8 @@
         else:
             self.inset_box_args = inset_box_args
         self.draw_inset_box = draw_inset_box
+        if text_args is None:
+            text_args = {}
         self.text_args = text_args
 
     def __call__(self, plot):
@@ -1922,10 +1924,10 @@
         if self.text_args is not None:
             # FontProperties instances use private attributes, so prepend 
             # text_args with _
-            for key in self.text_args:
+            for key, val in self.text_args.items():
                 setter_func = "set_"+key
                 try: 
-                    getattr(fontproperties, setter_func)(self.text_args[key])
+                    getattr(fontproperties, setter_func)(val)
                 except AttributeError:
                     raise AttributeError("Cannot set text_args keyword " \
                     "to include '%s' because MPL's fontproperties object does " \


https://bitbucket.org/yt_analysis/yt/commits/d4e23aad3230/
Changeset:   d4e23aad3230
Branch:      yt
User:        xarthisius
Date:        2015-08-20 20:58:30+00:00
Summary:     Add tests for annotate_scale(text_args=)
Affected #:  1 file

diff -r 101bde78685605fe00d89ff389f6aae69f8e8933 -r d4e23aad323053a7e2f6683f229dc3bda84db87a yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -15,11 +15,15 @@
 #-----------------------------------------------------------------------------
 import tempfile
 import shutil
+from numpy.testing import \
+    assert_raises
 
 from yt.testing import \
     fake_amr_ds
 import yt.units as u
 from .test_plotwindow import assert_fname
+from yt.utilities.exceptions import \
+    YTPlotCallbackError
 from yt.visualization.api import \
     SlicePlot, ProjectionPlot, OffAxisSlicePlot
 import contextlib
@@ -78,7 +82,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_timestamp(corner='lower_right', redshift=True, 
+        p.annotate_timestamp(corner='lower_right', redshift=True,
                              draw_inset_box=True)
         p.save(prefix)
 
@@ -99,7 +103,13 @@
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
         p.annotate_scale(corner='upper_right', coeff=10., unit='kpc')
-        p.save(prefix)
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"size": 24})
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"font": 24})
+        yield assert_raises, YTPlotCallbackError
 
 def test_line_callback():
     with _cleanup_fname() as prefix:
@@ -117,7 +127,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis', 
+        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis',
                         plot_args={'color':'red'})
         p.save(prefix)
 
@@ -345,7 +355,7 @@
             yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line_integral_convolution("velocity_x", "velocity_y", 
+        p.annotate_line_integral_convolution("velocity_x", "velocity_y",
                                              kernellen=100., lim=(0.4,0.7),
                                              cmap='algae', alpha=0.9,
                                              const_alpha=True)


https://bitbucket.org/yt_analysis/yt/commits/0df15b48bf45/
Changeset:   0df15b48bf45
Branch:      yt
User:        chummels
Date:        2015-08-20 22:09:33+00:00
Summary:     Merged in xarthisius/yt (pull request #1)

Add tests for annotate_scale(text_args=)
Affected #:  1 file

diff -r 5caf5a831e6f9b389fa1a268ab2c27830da6f525 -r 0df15b48bf45cd8696243d885ad44e180a05d8fb yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -15,11 +15,15 @@
 #-----------------------------------------------------------------------------
 import tempfile
 import shutil
+from numpy.testing import \
+    assert_raises
 
 from yt.testing import \
     fake_amr_ds
 import yt.units as u
 from .test_plotwindow import assert_fname
+from yt.utilities.exceptions import \
+    YTPlotCallbackError
 from yt.visualization.api import \
     SlicePlot, ProjectionPlot, OffAxisSlicePlot
 import contextlib
@@ -78,7 +82,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_timestamp(corner='lower_right', redshift=True, 
+        p.annotate_timestamp(corner='lower_right', redshift=True,
                              draw_inset_box=True)
         p.save(prefix)
 
@@ -99,7 +103,13 @@
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
         p.annotate_scale(corner='upper_right', coeff=10., unit='kpc')
-        p.save(prefix)
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"size": 24})
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"font": 24})
+        yield assert_raises, YTPlotCallbackError
 
 def test_line_callback():
     with _cleanup_fname() as prefix:
@@ -117,7 +127,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis', 
+        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis',
                         plot_args={'color':'red'})
         p.save(prefix)
 
@@ -345,7 +355,7 @@
             yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line_integral_convolution("velocity_x", "velocity_y", 
+        p.annotate_line_integral_convolution("velocity_x", "velocity_y",
                                              kernellen=100., lim=(0.4,0.7),
                                              cmap='algae', alpha=0.9,
                                              const_alpha=True)


https://bitbucket.org/yt_analysis/yt/commits/0795ab36f68b/
Changeset:   0795ab36f68b
Branch:      yt
User:        chummels
Date:        2015-08-21 16:54:27+00:00
Summary:     Getting rid of unnecessary conditional in annotate_scale()
Affected #:  1 file

diff -r 5caf5a831e6f9b389fa1a268ab2c27830da6f525 -r 0795ab36f68b9064abf3b1b05f56d68b2ee0509c yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1921,17 +1921,15 @@
         fontproperties = self.size_bar_args.pop(
             'fontproperties', plot.font_properties.copy())
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
-        if self.text_args is not None:
-            # FontProperties instances use private attributes, so prepend 
-            # text_args with _
-            for key, val in self.text_args.items():
-                setter_func = "set_"+key
-                try: 
-                    getattr(fontproperties, setter_func)(val)
-                except AttributeError:
-                    raise AttributeError("Cannot set text_args keyword " \
-                    "to include '%s' because MPL's fontproperties object does " \
-                    "not contain function '%s'." % (key, setter_func))
+        # FontProperties instances use set_<property>() setter functions
+        for key, val in self.text_args.items():
+            setter_func = "set_"+key
+            try: 
+                getattr(fontproperties, setter_func)(val)
+            except AttributeError:
+                raise AttributeError("Cannot set text_args keyword " \
+                "to include '%s' because MPL's fontproperties object does " \
+                "not contain function '%s'." % (key, setter_func))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/264ca8edeaab/
Changeset:   264ca8edeaab
Branch:      yt
User:        chummels
Date:        2015-08-21 16:59:12+00:00
Summary:     Merging.
Affected #:  1 file

diff -r 0df15b48bf45cd8696243d885ad44e180a05d8fb -r 264ca8edeaabc1ec08a3bd51898d486f4d585c0e yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1921,17 +1921,15 @@
         fontproperties = self.size_bar_args.pop(
             'fontproperties', plot.font_properties.copy())
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
-        if self.text_args is not None:
-            # FontProperties instances use private attributes, so prepend 
-            # text_args with _
-            for key, val in self.text_args.items():
-                setter_func = "set_"+key
-                try: 
-                    getattr(fontproperties, setter_func)(val)
-                except AttributeError:
-                    raise AttributeError("Cannot set text_args keyword " \
-                    "to include '%s' because MPL's fontproperties object does " \
-                    "not contain function '%s'." % (key, setter_func))
+        # FontProperties instances use set_<property>() setter functions
+        for key, val in self.text_args.items():
+            setter_func = "set_"+key
+            try: 
+                getattr(fontproperties, setter_func)(val)
+            except AttributeError:
+                raise AttributeError("Cannot set text_args keyword " \
+                "to include '%s' because MPL's fontproperties object does " \
+                "not contain function '%s'." % (key, setter_func))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates


https://bitbucket.org/yt_analysis/yt/commits/0d479d8c21a4/
Changeset:   0d479d8c21a4
Branch:      yt
User:        MatthewTurk
Date:        2015-08-21 17:55:07+00:00
Summary:     Merged in chummels/yt (pull request #1705)

Adding `text_args` keyword to `annotate_scale()` callback
Affected #:  3 files

diff -r 217242c6330948690759927cb2ecdf64289e54e5 -r 0d479d8c21a4557c8fc17329c0171ff6dec4e8e8 doc/source/visualizing/callbacks.rst
--- a/doc/source/visualizing/callbacks.rst
+++ b/doc/source/visualizing/callbacks.rst
@@ -597,23 +597,27 @@
 
 Add a Physical Scale Bar
 ~~~~~~~~~~~~~~~~~~~~~~~~
-
 .. function:: annotate_scale(corner='lower_right', coeff=None, \
-                             unit=None, pos=None, max_frac=0.2, \
-                             min_frac=0.018, text_args=None, \
-                             inset_box_args=None)
+                             unit=None, pos=None, max_frac=0.16, \
+                             min_frac=0.015, coord_system='axis', \
+                             text_args=None, size_bar_args=None, \
+                             draw_inset_box=False, inset_box_args=None)
 
    (This is a proxy for
    :class:`~yt.visualization.plot_modifications.ScaleCallback`.)
 
     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) 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 text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in
+    matplotlib's axes_grid toolkit.
 
 .. python-script::
 

diff -r 217242c6330948690759927cb2ecdf64289e54e5 -r 0d479d8c21a4557c8fc17329c0171ff6dec4e8e8 yt/visualization/plot_modifications.py
--- a/yt/visualization/plot_modifications.py
+++ b/yt/visualization/plot_modifications.py
@@ -1738,7 +1738,7 @@
     """
     annotate_scale(corner='lower_right', coeff=None, unit=None, pos=None,
                    max_frac=0.16, min_frac=0.015, coord_system='axis',
-                   size_bar_args=None, draw_inset_box=False,
+                   text_args=None, 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
@@ -1748,8 +1748,11 @@
     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.
+    adjusting the text_args and size_bar_args dictionaries.  The text_args
+    dictionary accepts matplotlib's font_properties arguments to override
+    the default font_properties for the current plot.  The size_bar_args 
+    dictionary accepts keyword arguments for the AnchoredSizeBar class in 
+    matplotlib's axes_grid toolkit.
 
     Parameters
     ----------
@@ -1796,6 +1799,12 @@
             "figure" -- the MPL figure coordinates: (0,0) is lower left, (1,1)
                         is upper right
 
+    text_args : dictionary, optional
+        A dictionary of parameters to used to update the font_properties
+        for the text in this callback.  For any property not set, it will
+        use the defaults of the plot.  Thus one can modify the text size with:
+        text_args={'size':24}
+
     size_bar_args : dictionary, optional
         A dictionary of parameters to be passed to the Matplotlib
         AnchoredSizeBar initializer.
@@ -1822,7 +1831,8 @@
     _type_name = "scale"
     def __init__(self, corner='lower_right', coeff=None, unit=None, pos=None,
                  max_frac=0.16, min_frac=0.015, coord_system='axis',
-                 size_bar_args=None, draw_inset_box=False, inset_box_args=None):
+                 text_args=None, size_bar_args=None, draw_inset_box=False, 
+                 inset_box_args=None):
 
         def_size_bar_args = {
             'pad': 0.05,
@@ -1856,6 +1866,9 @@
         else:
             self.inset_box_args = inset_box_args
         self.draw_inset_box = draw_inset_box
+        if text_args is None:
+            text_args = {}
+        self.text_args = text_args
 
     def __call__(self, plot):
         # Callback only works for plots with axis ratios of 1
@@ -1906,8 +1919,17 @@
 
         size_vertical = self.size_bar_args.pop('size_vertical', .005)
         fontproperties = self.size_bar_args.pop(
-            'fontproperties', plot.font_properties)
+            'fontproperties', plot.font_properties.copy())
         frameon = self.size_bar_args.pop('frameon', self.draw_inset_box)
+        # FontProperties instances use set_<property>() setter functions
+        for key, val in self.text_args.items():
+            setter_func = "set_"+key
+            try: 
+                getattr(fontproperties, setter_func)(val)
+            except AttributeError:
+                raise AttributeError("Cannot set text_args keyword " \
+                "to include '%s' because MPL's fontproperties object does " \
+                "not contain function '%s'." % (key, setter_func))
 
         # this "anchors" the size bar to a box centered on self.pos in axis
         # coordinates

diff -r 217242c6330948690759927cb2ecdf64289e54e5 -r 0d479d8c21a4557c8fc17329c0171ff6dec4e8e8 yt/visualization/tests/test_callbacks.py
--- a/yt/visualization/tests/test_callbacks.py
+++ b/yt/visualization/tests/test_callbacks.py
@@ -15,11 +15,15 @@
 #-----------------------------------------------------------------------------
 import tempfile
 import shutil
+from numpy.testing import \
+    assert_raises
 
 from yt.testing import \
     fake_amr_ds
 import yt.units as u
 from .test_plotwindow import assert_fname
+from yt.utilities.exceptions import \
+    YTPlotCallbackError
 from yt.visualization.api import \
     SlicePlot, ProjectionPlot, OffAxisSlicePlot
 import contextlib
@@ -78,7 +82,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_timestamp(corner='lower_right', redshift=True, 
+        p.annotate_timestamp(corner='lower_right', redshift=True,
                              draw_inset_box=True)
         p.save(prefix)
 
@@ -99,7 +103,13 @@
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
         p.annotate_scale(corner='upper_right', coeff=10., unit='kpc')
-        p.save(prefix)
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"size": 24})
+        yield assert_fname, p.save(prefix)[0]
+        p = SlicePlot(ds, "x", "density")
+        p.annotate_scale(text_args={"font": 24})
+        yield assert_raises, YTPlotCallbackError
 
 def test_line_callback():
     with _cleanup_fname() as prefix:
@@ -117,7 +127,7 @@
         yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis', 
+        p.annotate_line([0.1,0.1],[0.5,0.5], coord_system='axis',
                         plot_args={'color':'red'})
         p.save(prefix)
 
@@ -345,7 +355,7 @@
             yield assert_fname, p.save(prefix)[0]
         # Now we'll check a few additional minor things
         p = SlicePlot(ds, "x", "density")
-        p.annotate_line_integral_convolution("velocity_x", "velocity_y", 
+        p.annotate_line_integral_convolution("velocity_x", "velocity_y",
                                              kernellen=100., lim=(0.4,0.7),
                                              cmap='algae', alpha=0.9,
                                              const_alpha=True)

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