SF.net SVN: matplotlib:[7259] trunk/matplotlib
Revision: 7259
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7259&view=rev
Author: leejjoon
Date: 2009-07-14 19:21:47 + (Tue, 14 Jul 2009)
Log Message:
---
Fix a few bugs in ConnectionStyle classes. Add ConnectionPatch.
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/patches.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-07-12 03:20:53 UTC (rev 7258)
+++ trunk/matplotlib/CHANGELOG 2009-07-14 19:21:47 UTC (rev 7259)
@@ -1,3 +1,6 @@
+2009-07-14 Fix a few bugs in ConnectionStyle algorithms. Add
+ ConnectionPatch class. -JJL
+
2009-07-11 Added a fillstyle Line2D property for half filled markers
-- see examples/pylab_examples/fillstyle_demo.py JDH
Modified: trunk/matplotlib/lib/matplotlib/patches.py
===
--- trunk/matplotlib/lib/matplotlib/patches.py 2009-07-12 03:20:53 UTC (rev
7258)
+++ trunk/matplotlib/lib/matplotlib/patches.py 2009-07-14 19:21:47 UTC (rev
7259)
@@ -1729,8 +1729,8 @@
"""
def __init__(self, pad=0.3):
-self.pad = pad
-super(BoxStyle.RArrow, self).__init__()
+#self.pad = pad
+super(BoxStyle.RArrow, self).__init__(pad)
def transmute(self, x0, y0, width, height, mutation_size):
@@ -2466,7 +2466,7 @@
cosA, sinA = math.cos(self.angleA/180.*math.pi),\
math.sin(self.angleA/180.*math.pi),
cosB, sinB = math.cos(self.angleB/180.*math.pi),\
- -math.sin(self.angleB/180.*math.pi),
+ math.sin(self.angleB/180.*math.pi),
cx, cy = get_intersection(x1, y1, cosA, sinA,
x2, y2, cosB, sinB)
@@ -2478,9 +2478,15 @@
vertices.append((cx, cy))
codes.append(Path.LINETO)
else:
-vertices.extend([(cx - self.rad * cosA, cy - self.rad * sinA),
+dx1, dy1 = x1-cx, y1-cy
+d1 = (dx1**2 + dy1**2)**.5
+f1 = self.rad/d1
+dx2, dy2 = x2-cx, y2-cy
+d2 = (dx2**2 + dy2**2)**.5
+f2 = self.rad/d2
+vertices.extend([(cx + dx1*f1, cy + dy1*f1),
(cx, cy),
- (cx + self.rad * cosB, cy + self.rad * sinB)])
+ (cx + dx2*f2, cy + dy2*f2)])
codes.extend([Path.LINETO, Path.CURVE3, Path.CURVE3])
vertices.append((x2, y2))
@@ -2623,7 +2629,8 @@
#angle = self.angle % 180.
#if angle < 0. or angle > 180.:
#angle
-theta0 = (self.angle%180.)/180.*math.pi
+#theta0 = (self.angle%180.)/180.*math.pi
+theta0 = self.angle/180.*math.pi
#theta0 = (((self.angle+90)%180.) - 90.)/180.*math.pi
dtheta = theta1 - theta0
dl = dd*math.sin(dtheta)
@@ -3744,3 +3751,302 @@
gc.restore()
renderer.close_group('patch')
+
+
+class ConnectionPatch(FancyArrowPatch):
+"""
+A :class:`~matplotlib.patches.ConnectionPatch` class is to make
+connecting lines between two points (possibly in different axes).
+"""
+def __str__(self):
+return "ConnectionPatch((%g,%g),(%g,%g))" % \
+ (self.xy1[0],self.xy1[1],self.xy2[0],self.xy2[1])
+
+def __init__(self, xyA, xyB, coordsA, coordsB=None,
+ axesA=None, axesB=None,
+ arrowstyle="-",
+ arrow_transmuter=None,
+ connectionstyle="arc3",
+ connector=None,
+ patchA=None,
+ patchB=None,
+ shrinkA=0.,
+ shrinkB=0.,
+ mutation_scale=10.,
+ mutation_aspect=None,
+ clip_on=False,
+ **kwargs):
+"""
+Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*
+
+
+Valid keys are
+
+
+=== ==
+Key Description
+=== ==
+arrowstyle the arrow style
+connectionstyle the connection style
+relpos default is (0.5, 0.5)
+patchA default is bounding box of the text
+patchB default is None
+shrinkA default is 2 points
+shrinkB default is 2 points
+mutation_scale default is text size (in points)
+mutation_aspect default is 1.
+?any key for :class:`matplotlib.patches.PathPatch`
+===
SF.net SVN: matplotlib:[7260] trunk/matplotlib/lib/mpl_toolkits/mplot3d/ axes3d.py
Revision: 7260 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7260&view=rev Author: heeres Date: 2009-07-14 21:11:53 + (Tue, 14 Jul 2009) Log Message: --- Fix mplot3d bug with empty lists thanks to Ryan Wagner. Modified Paths: -- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py Modified: trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py === --- trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-14 19:21:47 UTC (rev 7259) +++ trunk/matplotlib/lib/mpl_toolkits/mplot3d/axes3d.py 2009-07-14 21:11:53 UTC (rev 7260) @@ -633,11 +633,14 @@ shade = np.array(shade) mask = ~np.isnan(shade) -norm = Normalize(min(shade[mask]), max(shade[mask])) -color = color.copy() -color[3] = 1 -colors = [color * (0.5 + norm(v) * 0.5) for v in shade] + if len(shade[mask]) > 0: + norm = Normalize(min(shade[mask]), max(shade[mask])) + color = color.copy() + color[3] = 1 + colors = [color * (0.5 + norm(v) * 0.5) for v in shade] +else: + colors = color.copy() return colors @@ -707,6 +710,12 @@ polyverts = [] normals = [] nsteps = round(len(topverts[0]) / stride) +if nsteps <= 1: +if len(topverts[0]) > 1: +nsteps = 2 +else: +continue + stepsize = (len(topverts[0]) - 1) / (nsteps - 1) for i in range(int(round(nsteps)) - 1): i1 = int(round(i * stepsize)) @@ -719,11 +728,11 @@ v1 = np.array(topverts[0][i1]) - np.array(topverts[0][i2]) v2 = np.array(topverts[0][i1]) - np.array(botverts[0][i1]) normals.append(np.cross(v1, v2)) - + colors = self._shade_colors(color, normals) colors2 = self._shade_colors(color, normals) polycol = art3d.Poly3DCollection(polyverts, facecolors=colors, -edgecolors=colors2) +edgecolors=colors2) self.add_collection3d(polycol) for col in colls: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. -- Enter the BlackBerry Developer Challenge This is your chance to win up to $100,000 in prizes! For a limited time, vendors submitting new applications to BlackBerry App World(TM) will have the opportunity to enter the BlackBerry Developer Challenge. See full prize details at: http://p.sf.net/sfu/Challenge ___ Matplotlib-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins
SF.net SVN: matplotlib:[7261] trunk/matplotlib
Revision: 7261 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7261&view=rev Author: leejjoon Date: 2009-07-14 21:18:58 + (Tue, 14 Jul 2009) Log Message: --- axes_grid : minor improvements in anchored_artists and inset_locator. Modified Paths: -- trunk/matplotlib/CHANGELOG trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/axes_grid.py trunk/matplotlib/lib/mpl_toolkits/axes_grid/inset_locator.py Modified: trunk/matplotlib/CHANGELOG === --- trunk/matplotlib/CHANGELOG 2009-07-14 21:11:53 UTC (rev 7260) +++ trunk/matplotlib/CHANGELOG 2009-07-14 21:18:58 UTC (rev 7261) @@ -1,3 +1,6 @@ +2009-07-14 axes_grid : minor improvements in anchored_artists and + inset_locator. -JJL + 2009-07-14 Fix a few bugs in ConnectionStyle algorithms. Add ConnectionPatch class. -JJL Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py === --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py 2009-07-14 21:11:53 UTC (rev 7260) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/__init__.py 2009-07-14 21:18:58 UTC (rev 7261) @@ -1,10 +1,6 @@ -""" -AxesGrid -""" - import axes_size as Size from axes_divider import Divider, SubplotDivider, LocatableAxes, \ make_axes_locatable -from axes_grid import AxesGrid +from axes_grid import Grid, ImageGrid, AxesGrid #from axes_divider import make_axes_locatable Modified: trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py === --- trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py 2009-07-14 21:11:53 UTC (rev 7260) +++ trunk/matplotlib/lib/mpl_toolkits/axes_grid/anchored_artists.py 2009-07-14 21:18:58 UTC (rev 7261) @@ -21,34 +21,37 @@ **kwargs) -class AnchoredSizeBar(AnchoredOffsetbox): -def __init__(self, transform, size, label, loc, - pad=0.1, borderpad=0.1, sep=2, prop=None, frameon=True): -""" -Draw a horizontal bar with the size in data coordinate of the give axes. -A label will be drawn underneath (center-alinged). -pad, borderpad in fraction of the legend font size (or prop) -sep in points. -""" -self.size_bar = AuxTransformBox(transform) -self.size_bar.add_artist(Rectangle((0,0), size, 0, fc="none")) +class AnchoredDrawingArea(AnchoredOffsetbox): +def __init__(self, width, height, xdescent, ydescent, + loc, pad=0.4, borderpad=0.5, prop=None, frameon=True, + **kwargs): -self.txt_label = TextArea(label, minimumdescent=False) +self.da = DrawingArea(width, height, xdescent, ydescent, clip=True) +self.drawing_area = self.da + +super(AnchoredDrawingArea, self).__init__(loc, pad=pad, borderpad=borderpad, + child=self.da, + prop=None, + frameon=frameon, + **kwargs) -self._box = VPacker(children=[self.size_bar, self.txt_label], -align="center", -pad=0, sep=sep) +class AnchoredAuxTransformBox(AnchoredOffsetbox): +def __init__(self, transform, loc, + pad=0.4, borderpad=0.5, prop=None, frameon=True, **kwargs): +self.drawing_area = AuxTransformBox(transform) + AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad, - child=self._box, + child=self.drawing_area, prop=prop, - frameon=frameon) + frameon=frameon, + **kwargs) class AnchoredEllipse(AnchoredOffsetbox): def __init__(self, transform, width, height, angle, loc, - pad=0.1, borderpad=0.1, prop=None, frameon=True): + pad=0.1, borderpad=0.1, prop=None, frameon=True, **kwargs): """ Draw an ellipse the size in data coordinate of the give axes. @@ -61,20 +64,32 @@ AnchoredOffsetbox.__init__(self, loc, pad=pad, borderpad=borderpad, child=self._box, prop=prop, - frameon=frameon) + frameon=frameon, **kwargs) -class AnchoredDrawingArea(AnchoredOffsetbox): -def __init__(self, width, height, xdescent, ydescent, - loc, pad=0.4, borderpad=0.5,
SF.net SVN: matplotlib:[7262] trunk/matplotlib
Revision: 7262
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7262&view=rev
Author: leejjoon
Date: 2009-07-14 21:24:07 + (Tue, 14 Jul 2009)
Log Message:
---
initial submission of the annotation guide.
Modified Paths:
--
trunk/matplotlib/CHANGELOG
trunk/matplotlib/doc/users/plotting.rst
Added Paths:
---
trunk/matplotlib/doc/users/plotting/annotation.rst
trunk/matplotlib/doc/users/plotting/examples/anchored_box01.py
trunk/matplotlib/doc/users/plotting/examples/anchored_box02.py
trunk/matplotlib/doc/users/plotting/examples/anchored_box03.py
trunk/matplotlib/doc/users/plotting/examples/anchored_box04.py
trunk/matplotlib/doc/users/plotting/examples/annotate_explain.py
trunk/matplotlib/doc/users/plotting/examples/annotate_simple01.py
trunk/matplotlib/doc/users/plotting/examples/annotate_simple02.py
trunk/matplotlib/doc/users/plotting/examples/annotate_simple03.py
trunk/matplotlib/doc/users/plotting/examples/annotate_simple04.py
trunk/matplotlib/doc/users/plotting/examples/annotate_text_arrow.py
trunk/matplotlib/doc/users/plotting/examples/axes_zoom_effect.py
trunk/matplotlib/doc/users/plotting/examples/connect_simple01.py
trunk/matplotlib/doc/users/plotting/examples/connectionstyle_demo.py
trunk/matplotlib/doc/users/plotting/examples/custom_boxstyle01.py
trunk/matplotlib/doc/users/plotting/examples/custom_boxstyle02.py
trunk/matplotlib/doc/users/plotting/examples/simple_annotate01.py
trunk/matplotlib/examples/pylab_examples/axes_zoom_effect.py
Modified: trunk/matplotlib/CHANGELOG
===
--- trunk/matplotlib/CHANGELOG 2009-07-14 21:18:58 UTC (rev 7261)
+++ trunk/matplotlib/CHANGELOG 2009-07-14 21:24:07 UTC (rev 7262)
@@ -1,3 +1,5 @@
+2009-07-14 initial submission of the annotation guide. -JJL
+
2009-07-14 axes_grid : minor improvements in anchored_artists and
inset_locator. -JJL
Added: trunk/matplotlib/doc/users/plotting/annotation.rst
===
--- trunk/matplotlib/doc/users/plotting/annotation.rst
(rev 0)
+++ trunk/matplotlib/doc/users/plotting/annotation.rst 2009-07-14 21:24:07 UTC
(rev 7262)
@@ -0,0 +1,332 @@
+.. _plotting-guide-annotation:
+
+
+Annotating Axes
+
+
+Do not proceed unless you already have read
+:func:`~matplotlib.pyplot.text` and :func:`~matplotlib.pyplot.annotate`!
+
+
+Annotating with Text with Box
+=
+
+Let's start with a simple example.
+
+.. plot:: users/plotting/examples/annotate_text_arrow.py
+
+
+The :func:`~matplotlib.pyplot.text` function in the pyplot module (or
+text method of the Axes class) takes bbox keyword argument, and when
+given, a box around the text is drawn. ::
+
+bbox_props = dict(boxstyle="rarrow,pad=0.3", fc="cyan", ec="b", lw=2)
+t = ax.text(0, 0, "Direction", ha="center", va="center", rotation=45,
+size=15,
+bbox=bbox_props)
+
+
+The patch object associated with the text can be accessed by::
+
+bb = t.get_bbox_patch()
+
+The return value is an instance of FancyBboxPatch and the patch
+properties like facecolor, edgewidth, etc. can be accessed and
+modified as usual. To change the shape of the box, use *set_boxstyle*
+method. ::
+
+ bb.set_boxstyle("rarrow", pad=0.6)
+
+The arguments are the name of the box style with its attributes as
+keyword arguments. Currently, followign box styles are implemented.
+
+ == == ==
+ ClassName Attrs
+ == == ==
+ LArrow ``larrow`` pad=0.3
+ RArrow ``rarrow`` pad=0.3
+ Round``round``pad=0.3,rounding_size=None
+ Round4 ``round4`` pad=0.3,rounding_size=None
+ Roundtooth ``roundtooth`` pad=0.3,tooth_size=None
+ Sawtooth ``sawtooth`` pad=0.3,tooth_size=None
+ Square ``square`` pad=0.3
+ == == ==
+
+.. plot:: mpl_examples/pylab_examples/fancybox_demo2.py
+
+
+Note that the attrubutes arguments can be specified within the style
+name with separating comma (this form can be used as "boxstyle" value
+of bbox argument when initializing the text instance) ::
+
+ bb.set_boxstyle("rarrow,pad=0.6")
+
+
+
+
+Annotating with Arrow
+=
+
+The :func:`~matplotlib.pyplot.annotate` function in the pyplot module
+(or annotate method of the Axes class) is used to draw an arrow
+connecting two points on the plot. ::
+
+ax.annotate("Annotation",
+xy=(x1, y1), xycoords='data',
+xytext=(x2, y2), textcoords='offset points',
+)
+
+This annotates a point at ``xy`` in the given coordinate (``xycoords``)
+with the text at ``xytext`` given in ``t
