[yt-svn] commit/yt: MatthewTurk: Merged in chummels/yt (pull request #1705)

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


1 new commit in yt:

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