<html><body>
<p>1 new commit in yt:</p>
<p><a href="https://bitbucket.org/yt_analysis/yt/commits/bba384360818/">https://bitbucket.org/yt_analysis/yt/commits/bba384360818/</a> Changeset: bba384360818 Branch: yt User: brittonsmith Date: 2016-03-28 08:42:09+00:00 Summary: Merged in chummels/yt (pull request #2043)</p>
<p>Enhancing annotate_ray and annotate_arrow callbacks Affected #: 1 file</p>
<p>diff -r be993079427c300e09b4b6430e3c8d90af0c3500 -r bba3843608189ecf29b8ad109ae02546bbd272af yt/visualization/plot_modifications.py --- a/yt/visualization/plot_modifications.py +++ b/yt/visualization/plot_modifications.py @@ -158,6 +158,9 @@</p>
<pre> "need to be in 3D")
coord = self.project_coords(plot, coord)
coord = self.convert_to_plot(plot, coord)</pre>
<p>+ # Convert coordinates from a tuple of ndarray to a tuple of floats + # since not all callbacks are OK with ndarrays as coords (eg arrow) + coord = (coord[0][0], coord[1][0])</p>
<pre> # if in plot coords, define the transform correctly
if coord_system == "data" or coord_system == "plot":
self.transform = plot._axes.transData</pre>
<p>@@ -905,11 +908,23 @@</p>
<pre>class ArrowCallback(PlotCallback):
"""</pre>
<ul><li><p>annotate_arrow(pos, length=0.03, coord_system='data', plot_args=None):</p></li></ul>
<p>+ annotate_arrow(pos, length=0.03, width=0.003, head_length=None, + head_width=0.02, starting_pos=None, + coord_system='data', plot_args=None):</p>
<pre>Overplot an arrow pointing at a position for highlighting a specific</pre>
<ul><li><p>feature. Arrow points from lower left to the designated position with</p></li>
<li><p>arrow length “length”.</p></li></ul>
<p>+ feature. By default, arrow points from lower left to the designated + position “pos” with arrow length “length”. Alternatively, if + “starting_pos” is set, arrow will stretch from “starting_pos” to “pos” + and “length” will be disregarded. + + “coord_system” keyword refers to positions set in “pos” arg and + “starting_pos” keyword, which by default are in data coordinates. + + “length”, “width”, “head_length”, and “head_width” keywords for the arrow + are all in axis units, ie relative to the size of the plot axes as 1, + even if the position of the arrow is set relative to another coordinate + system.</p>
<pre>Parameters
----------</pre>
<p>@@ -918,6 +933,24 @@</p>
<pre>length : float, optional
The length, in axis units, of the arrow.</pre>
<p>+ Default: 0.03 + + width : float, optional + The width, in axis units, of the tail line of the arrow. + Default: 0.003 + + head_length : float, optional + The length, in axis units, of the head of the arrow. If set + to None, use 1.5*head_width + Default: None + + head_width : float, optional + The width, in axis units, of the head of the arrow. + Default: 0.02 + + starting_pos : 2- or 3-element tuple, list, or array, optional + These are the coordinates from which the arrow starts towards its + point. Not compatible with ‘length’ kwarg.</p>
<pre>coord_system : string, optional
This string defines the coordinate system of the coordinates of pos</pre>
<p>@@ -935,7 +968,7 @@</p>
<pre>plot_args : dictionary, optional
This dictionary is passed to the MPL arrow function for generating</pre>
<ul><li><p>the arrow. By default, it is: {'color':'white', 'linewidth':2}</p></li></ul>
<p>+ the arrow. By default, it is: {'color':'white'}</p>
<pre>Examples
--------</pre>
<p>@@ -952,18 +985,23 @@</p>
<pre>>>> import yt
>>> ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
>>> s = yt.SlicePlot(ds, 'z', 'density')</pre>
<ul><li><blockquote><blockquote><blockquote><p>s.annotate_arrow([0.1, -0.1, length=0.06, coord_system='plot',</p></blockquote></blockquote></blockquote></li></ul>
<p>+ >>> s.annotate_arrow([0.1, -0.1], length=0.06, coord_system='plot',</p>
<pre> ... plot_args={'color':'red'})
>>> s.save()
"""
_type_name = "arrow"</pre>
<ul><li><p>def __init__(self, pos, code_size=None, length=0.03, coord_system='data',</p></li>
<li><p>plot_args=None):</p></li>
<li><p>def_plot_args = {'color':'white', 'linewidth':2}</p></li></ul>
<p>+ def __init__(self, pos, code_size=None, length=0.03, width=0.0001, + head_width=0.01, head_length=0.01, + starting_pos=None, coord_system='data', plot_args=None): + def_plot_args = {'color':'white'}</p>
<pre>self.pos = pos
self.code_size = code_size
self.length = length</pre>
<p>+ self.width = width + self.head_width = head_width + self.head_length = head_length + self.starting_pos = starting_pos</p>
<pre>self.coord_system = coord_system
self.transform = None
if plot_args is None: plot_args = def_plot_args</pre>
<p>@@ -974,7 +1012,13 @@</p>
<pre>coord_system=self.coord_system)
xx0, xx1 = plot._axes.get_xlim()
yy0, yy1 = plot._axes.get_ylim()</pre>
<p>– + # normalize all of the kwarg lengths to the plot size + plot_diag = ((yy1-yy0)**2 + (xx1-xx0)**2)**(0.5) + self.length *= plot_diag + self.width *= plot_diag + self.head_width *= plot_diag + if self.head_length is not None: + self.head_length *= plot_diag</p>
<pre> if self.code_size is not None:
warnings.warn("The code_size keyword is deprecated. Please use "
"the length keyword in 'axis' units instead. "</pre>
<p>@@ -985,13 +1029,25 @@</p>
<pre>self.code_size = self.code_size * self.pixel_scale(plot)[0]
dx = dy = self.code_size
else:</pre>
<ul><li><p>dx = (xx1-xx0) * self.length</p></li>
<li><p>dy = (yy1-yy0) * self.length</p></li></ul>
<p>+ if self.starting_pos is not None: + start_x,start_y = self.sanitize_coord_system(plot, + self.starting_pos, + coord_system=self.coord_system) + dx = x – start_x + dy = y – start_y + else: + dx = (xx1-xx0) * 2**(0.5) * self.length + dy = (yy1-yy0) * 2**(0.5) * self.length + # If the arrow is 0 length + if dx == dy == 0: + warnings.warn("The arrow has zero length. Not annotating.") + return</p>
<pre>plot._axes.hold(True)</pre>
<ul><li><p>from matplotlib.patches import Arrow</p></li>
<li><p>arrow = Arrow(x-dx, y-dy, dx, dy, width=dx,</p></li>
<li><p>transform=self.transform, **self.plot_args)</p></li>
<li><p>plot._axes.add_patch(arrow)</p></li></ul>
<p>+ plot._axes.arrow(x-dx, y-dy, dx, dy, width=self.width, + head_width=self.head_width, + head_length=self.head_length, + transform=self.transform, + length_includes_head=True, **self.plot_args)</p>
<pre>plot._axes.set_xlim(xx0,xx1)
plot._axes.set_ylim(yy0,yy1)
plot._axes.hold(False)</pre>
<p>@@ -1837,8 +1893,8 @@</p>
<pre>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</pre>
<ul><li><p>the default font_properties for the current plot. The size_bar_args</p></li>
<li><p>dictionary accepts keyword arguments for the AnchoredSizeBar class in</p></li></ul>
<p>+ the default font_properties for the current plot. The size_bar_args + dictionary accepts keyword arguments for the AnchoredSizeBar class in</p>
<pre> matplotlib's axes_grid toolkit.
Parameters</pre>
<p>@@ -1918,7 +1974,7 @@</p>
<pre> _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',</pre>
<ul><li><p>text_args=None, size_bar_args=None, draw_inset_box=False,</p></li></ul>
<p>+ text_args=None, size_bar_args=None, draw_inset_box=False,</p>
<pre> inset_box_args=None):
def_size_bar_args = {</pre>
<p>@@ -2011,7 +2067,7 @@</p>
<pre> # FontProperties instances use set_<property>() setter functions
for key, val in self.text_args.items():
setter_func = "set_"+key</pre>
<ul><li><p>try:</p></li></ul>
<p>+ try:</p>
<pre> getattr(fontproperties, setter_func)(val)
except AttributeError:
raise AttributeError("Cannot set text_args keyword " \</pre>
<p>@@ -2042,6 +2098,9 @@</p>
<pre>Adds a line representing the projected path of a ray across the plot.
The ray can be either a YTOrthoRay, YTRay, or a LightRay object.
annotate_ray() will properly account for periodic rays across the volume.</pre>
<p>+ If arrow is set to True, uses the MPL.pyplot.arrow function, otherwise + uses the MPL.pyplot.plot function to plot a normal line. Adjust + plot_args accordingly.</p>
<pre>Parameters
----------</pre>
<p>@@ -2053,6 +2112,11 @@</p>
<pre> object, it will only plot the segment of the LightRay that intersects
the dataset currently displayed.
</pre>
<p>+ arrow : boolean, optional + Whether or not to place an arrowhead on the front of the ray to denote + direction + Default: False +</p>
<pre>plot_args : dictionary, optional
A dictionary of any arbitrary parameters to be passed to the Matplotlib
line object. Defaults: {'color':'white', 'linewidth':2}.</pre>
<p>@@ -2083,10 +2147,11 @@</p>
<pre>"""
_type_name = "ray"</pre>
<ul><li><p>def __init__(self, ray, plot_args=None):</p></li></ul>
<p>+ def __init__(self, ray, arrow=False, plot_args=None):</p>
<pre>PlotCallback.__init__(self)
def_plot_args = {'color':'white', 'linewidth':2}
self.ray = ray</pre>
<p>+ self.arrow = arrow</p>
<pre> if plot_args is None: plot_args = def_plot_args
self.plot_args = plot_args
</pre>
<p>@@ -2156,12 +2221,23 @@</p>
<pre> else:
segments = [[start_coord, end_coord]]
</pre>
<ul><li><p>for segment in segments:</p></li>
<li><p>lcb = LinePlotCallback(segment[0], segment[1],</p></li>
<li><p>coord_system='data',</p></li>
<li><p>plot_args=self.plot_args)</p></li>
<li><p>lcb(plot)</p></li></ul>
<p>– + # To assure that the last ray segment has an arrow if so desired + # and all other ray segments are lines + for segment in segments[:-1]: + cb = LinePlotCallback(segment[0], segment[1], + coord_system='data', + plot_args=self.plot_args) + cb(plot) + segment = segments[-1] + if self.arrow: + cb = ArrowCallback(segment[1], starting_pos=segment[0], + coord_system='data', + plot_args=self.plot_args) + else: + cb = LinePlotCallback(segment[0], segment[1], + coord_system='data', + plot_args=self.plot_args) + cb(plot)</p>
<pre> return plot
class LineIntegralConvolutionCallback(PlotCallback):</pre>
<p>@@ -2171,7 +2247,7 @@</p>
<pre> cmap='binary', alpha=0.8,
const_alpha=False):
</pre>
<ul><li><p>Add the line integral convolution to the plot for vector fields</p></li></ul>
<p>+ Add the line integral convolution to the plot for vector fields</p>
<pre> visualization. Two component of vector fields needed to be provided
(i.e., velocity_x and velocity_y, magentic_field_x and magnetic_field_y).
</pre>
<p>@@ -2268,7 +2344,7 @@</p>
<pre> lic_data_clip = np.clip(lic_data,self.lim[0],self.lim[1])
if self.const_alpha:</pre>
<ul><li><p>plot._axes.imshow(lic_data_clip, extent=extent, cmap=self.cmap,</p></li></ul>
<p>+ plot._axes.imshow(lic_data_clip, extent=extent, cmap=self.cmap,</p>
<pre> alpha=self.alpha)
else:
lic_data_rgba = cm.ScalarMappable(norm=None, cmap=self.cmap).\</pre>
<p>Repository URL: <a href="https://bitbucket.org/yt_analysis/yt/">https://bitbucket.org/yt_analysis/yt/</a></p>
<p>—</p>
<p>This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.</p>
<img src="http://link.bitbucket.org/wf/open?upn=ll4ctv0L-2ByeRZFC1LslHcg6aJmnQ70VruLbmeLQr27CnWElix9iRXBK4hZvabC3n8FYBF8oNL7t9W71i524Q7Oj5FHBlS5fuk-2B4vdDR1dhOjU29ct6mhYvgMOei5uZv-2Fs7V5NY7y3FCAIT7PNvT9zb2am69RYDq62RmXWbFtvYJpk-2BInPV76fg2OeeEMfD0VBgI8ADk0-2BWGMmZUoBzb2mqrLSlOEQHX49dVlM-2BGIc28-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>