Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation: always use FancyBboxPatch instead of bbox_artist #4178

Merged
merged 9 commits into from Jul 22, 2015
40 changes: 20 additions & 20 deletions lib/matplotlib/patches.py
Expand Up @@ -2658,14 +2658,14 @@ class ConnectionStyle(_Style):

class _Base(object):
"""
A base class for connectionstyle classes. The dervided needs
to implement a *connect* methods whose call signature is::
A base class for connectionstyle classes. The subclass needs
to implement a *connect* method whose call signature is::

connect(posA, posB)

where posA and posB are tuples of x, y coordinates to be
connected. The methods needs to return a path connecting two
points. This base class defines a __call__ method, and few
connected. The method needs to return a path connecting two
points. This base class defines a __call__ method, and a few
helper methods.
"""

Expand Down Expand Up @@ -2738,18 +2738,18 @@ def __call__(self, posA, posB,
shrinkA=2., shrinkB=2., patchA=None, patchB=None):
"""
Calls the *connect* method to create a path between *posA*
and *posB*. The path is clipped and shrinked.
and *posB*. The path is clipped and shrunken.
"""

path = self.connect(posA, posB)

clipped_path = self._clip(path, patchA, patchB)
shrinked_path = self._shrink(clipped_path, shrinkA, shrinkB)
shrunk_path = self._shrink(clipped_path, shrinkA, shrinkB)

return shrinked_path
return shrunk_path

def __reduce__(self):
# because we have decided to nest thes classes, we need to
# because we have decided to nest these classes, we need to
# add some more information to allow instance pickling.
import matplotlib.cbook as cbook
return (cbook._NestedClassGetter(),
Expand Down Expand Up @@ -2994,7 +2994,7 @@ def connect(self, posA, posB):
class Bar(_Base):
"""
A line with *angle* between A and B with *armA* and
*armB*. One of the arm is extend so that they are connected in
*armB*. One of the arms is extended so that they are connected in
a right angle. The length of armA is determined by (*armA*
+ *fraction* x AB distance). Same for armB.
"""
Expand Down Expand Up @@ -3119,14 +3119,14 @@ class ArrowStyle(_Style):
%(AvailableArrowstyles)s


An instance of any arrow style class is an callable object,
An instance of any arrow style class is a callable object,
whose call signature is::

__call__(self, path, mutation_size, linewidth, aspect_ratio=1.)

and it returns a tuple of a :class:`Path` instance and a boolean
value. *path* is a :class:`Path` instance along witch the arrow
will be drawn. *mutation_size* and *aspect_ratio* has a same
value. *path* is a :class:`Path` instance along which the arrow
will be drawn. *mutation_size* and *aspect_ratio* have the same
meaning as in :class:`BoxStyle`. *linewidth* is a line width to be
stroked. This is meant to be used to correct the location of the
head so that it does not overshoot the destination point, but not all
Expand Down Expand Up @@ -3175,11 +3175,11 @@ def ensure_quadratic_bezier(path):

def transmute(self, path, mutation_size, linewidth):
"""
The transmute method is a very core of the ArrowStyle
The transmute method is the very core of the ArrowStyle
class and must be overriden in the subclasses. It receives
the path object along which the arrow will be drawn, and
the mutation_size, with which the amount arrow head and
etc. will be scaled. The linewidth may be used to adjust
the mutation_size, with which the arrow head etc.
will be scaled. The linewidth may be used to adjust
the path so that it does not pass beyond the given
points. It returns a tuple of a Path instance and a
boolean. The boolean value indicate whether the path can
Expand All @@ -3204,9 +3204,9 @@ def __call__(self, path, mutation_size, linewidth,
vertices, codes = path.vertices[:], path.codes[:]
# Squeeze the height
vertices[:, 1] = vertices[:, 1] / aspect_ratio
path_shrinked = Path(vertices, codes)
path_shrunk = Path(vertices, codes)
# call transmute method with squeezed height.
path_mutated, fillable = self.transmute(path_shrinked,
path_mutated, fillable = self.transmute(path_shrunk,
linewidth,
mutation_size)
if cbook.iterable(fillable):
Expand Down Expand Up @@ -3261,7 +3261,7 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
Return the paths for arrow heads. Since arrow lines are
drawn with capstyle=projected, The arrow goes beyond the
desired point. This method also returns the amount of the path
to be shrinked so that it does not overshoot.
to be shrunken so that it does not overshoot.
"""

# arrow from x0, y0 to x1, y1
Expand Down Expand Up @@ -3968,7 +3968,7 @@ def __init__(self, posA=None, posB=None,
"""
If *posA* and *posB* is given, a path connecting two point are
created according to the connectionstyle. The path will be
clipped with *patchA* and *patchB* and further shirnked by
clipped with *patchA* and *patchB* and further shrunken by
*shrinkA* and *shrinkB*. An arrow is drawn along this
resulting path using the *arrowstyle* parameter. If *path*
provided, an arrow is drawn along this path and *patchA*,
Expand Down Expand Up @@ -4077,7 +4077,7 @@ def set_connectionstyle(self, connectionstyle, **kw):

*connectionstyle* can be a string with connectionstyle name with
optional comma-separated attributes. Alternatively, the attrs can be
probided as keywords.
provided as keywords.

set_connectionstyle("arc,angleA=0,armA=30,rad=10")
set_connectionstyle("arc", angleA=0,armA=30,rad=10)
Expand Down
14 changes: 8 additions & 6 deletions lib/matplotlib/tests/test_text.py
Expand Up @@ -382,11 +382,11 @@ def test_text_with_arrow_annotation_get_window_extent():
# bounding box of annotation (text + arrow)
bbox = ann.get_window_extent(renderer=renderer)
# bounding box of arrow
arrow_bbox = ann.arrow.get_window_extent(renderer)
arrow_bbox = ann.arrow_patch.get_window_extent(renderer)
# bounding box of annotation text
ann_txt_bbox = Text.get_window_extent(ann)

# make sure annotation with in 50 px wider than
# make sure annotation width is 50 px wider than
# just the text
eq_(bbox.width, text_bbox.width + 50.0)
# make sure the annotation text bounding box is same size
Expand All @@ -400,12 +400,14 @@ def test_text_with_arrow_annotation_get_window_extent():

@cleanup
def test_arrow_annotation_get_window_extent():
figure = Figure(dpi=100)
dpi = 100
dots_per_point = dpi / 72
figure = Figure(dpi=dpi)
figure.set_figwidth(2.0)
figure.set_figheight(2.0)
renderer = RendererAgg(200, 200, 100)

# Text annotation with arrow
# Text annotation with arrow; arrow dimensions are in points
annotation = Annotation(
'', xy=(0.0, 50.0), xytext=(50.0, 50.0), xycoords='figure pixels',
arrowprops={
Expand All @@ -417,9 +419,9 @@ def test_arrow_annotation_get_window_extent():
points = bbox.get_points()

eq_(bbox.width, 50.0)
assert_almost_equal(bbox.height, 10.0 / 0.72)
assert_almost_equal(bbox.height, 10.0 * dots_per_point)
eq_(points[0, 0], 0.0)
eq_(points[0, 1], 50.0 - 5 / 0.72)
eq_(points[0, 1], 50.0 - 5 * dots_per_point)


@cleanup
Expand Down