8000 Merge pull request #4178 from efiring/annotate · matplotlib/matplotlib@bc185a2 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc185a2

Browse files
committed
Merge pull request #4178 from efiring/annotate
MNT: always use FancyBboxPatch instead of bbox_artist
2 parents 6c009db + 9eceef3 commit bc185a2

File tree

3 files changed

+161
-166
lines changed

3 files changed

+161
-166
lines changed

lib/matplotlib/patches.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,14 +2658,14 @@ class ConnectionStyle(_Style):
26582658

26592659
class _Base(object):
26602660
"""
2661-
A base class for connectionstyle classes. The dervided needs
2662-
to implement a *connect* methods whose call signature is::
2661+
A base class for connectionstyle classes. The subclass needs
2662+
to implement a *connect* method whose call signature is::
26632663
26642664
connect(posA, posB)
26652665
26662666
where posA and posB are tuples of x, y coordinates to be
2667-
connected. The methods needs to return a path connecting two
2668-
points. This base class defines a __call__ method, and few
2667+
connected. The method needs to return a path connecting two
2668+
points. This base class defines a __call__ method, and a few
26692669
helper methods.
26702670
"""
26712671

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

27442744
path = self.connect(posA, posB)
27452745

27462746
clipped_path = self._clip(path, patchA, patchB)
2747-
shrinked_path = self._shrink(clipped_path, shrinkA, shrinkB)
2747+
shrunk_path = self._shrink(clipped_path, shrinkA, shrinkB)
27482748

2749-
return shrinked_path
2749+
return shrunk_path
27502750

27512751
def __reduce__(self):
2752-
# because we have decided to nest thes classes, we need to
2752+
# because we have decided to nest these classes, we need to
27532753
# add some more information to allow instance pickling.
27542754
import matplotlib.cbook as cbook
27552755
return (cbook._NestedClassGetter(),
@@ -2994,7 +2994,7 @@ def connect(self, posA, posB):
29942994
class Bar(_Base):
29952995
"""
29962996
A line with *angle* between A and B with *armA* and
2997-
*armB*. One of the arm is extend so that they are connected in
2997+
*armB*. One of the arms is extended so that they are connected in
29982998
a right angle. The length of armA is determined by (*armA*
29992999
+ *fraction* x AB distance). Same for armB.
30003000
"""
@@ -3119,14 +3119,14 @@ class ArrowStyle(_Style):
31193119
%(AvailableArrowstyles)s
31203120
31213121
3122-
An instance of any arrow style class is an callable object,
3122+
An instance of any arrow style class is a callable object,
31233123
whose call signature is::
31243124
31253125
__call__(self, path, mutation_size, linewidth, aspect_ratio=1.)
31263126
31273127
and it returns a tuple of a :class:`Path` instance and a boolean
3128-
value. *path* is a :class:`Path` instance along witch the arrow
3129-
will be drawn. *mutation_size* and *aspect_ratio* has a same
3128+
value. *path* is a :class:`Path` instance along which the arrow
3129+
will be drawn. *mutation_size* and *aspect_ratio* have the same
31303130
meaning as in :class:`BoxStyle`. *linewidth* is a line width to be
31313131
stroked. This is meant to be used to correct the location of the
31323132
head so that it does not overshoot the destination point, but not all
@@ -3175,11 +3175,11 @@ def ensure_quadratic_bezier(path):
31753175

31763176
def transmute(self, path, mutation_size, linewidth):
31773177
"""
3178-
The transmute method is a very core of the ArrowStyle
3178+
The transmute method is the very core of the ArrowStyle
31793179
class and must be overriden in the subclasses. It receives
31803180
the path object along which the arrow will be drawn, and
3181-
the mutation_size, with which the amount arrow head and
3182-
etc. will be scaled. The linewidth may be used to adjust
3181+
the mutation_size, with which the arrow head etc.
3182+
will be scaled. The linewidth may be used to adjust
31833183
the path so that it does not pass beyond the given
31843184
points. It returns a tuple of a Path instance and a
31853185
boolean. The boolean value indicate whether the path can
@@ -3204,9 +3204,9 @@ def __call__(self, path, mutation_size, linewidth,
32043204
vertices, codes = path.vertices[:], path.codes[:]
32053205
# Squeeze the height
32063206
vertices[:, 1] = vertices[:, 1] / aspect_ratio
3207-
path_shrinked = Path(vertices, codes)
3207+
path_shrunk = Path(vertices, codes)
32083208
# call transmute method with squeezed height.
3209-
path_mutated, fillable = self.transmute(path_shrinked,
3209+
path_mutated, fillable = self.transmute(path_shrunk,
32103210
linewidth,
32113211
mutation_size)
32123212
if cbook.iterable(fillable):
@@ -3261,7 +3261,7 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
32613261
Return the paths for arrow heads. Since arrow lines are
32623262
drawn with capstyle=projected, The arrow goes beyond the
32633263
desired point. This method also returns the amount of the path
3264-
to be shrinked so that it does not overshoot.
3264+
to be shrunken so that it does not overshoot.
32653265
"""
32663266

32673267
# arrow from x0, y0 to x1, y1
@@ -3968,7 +3968,7 @@ def __init__(self, posA=None, posB=None,
39683968
"""
39693969
If *posA* and *posB* is given, a path connecting two point are
39703970
created according to the connectionstyle. The path will be
3971-
clipped with *patchA* and *patchB* and further shirnked by
3971+
clipped with *patchA* and *patchB* and further shrunken by
39723972
*shrinkA* and *shrinkB*. An arrow is drawn along this
39733973
resulting path using the *arrowstyle* parameter. If *path*
39743974
provided, an arrow is drawn along this path and *patchA*,
@@ -4077,7 +4077,7 @@ def set_connectionstyle(self, connectionstyle, **kw):
40774077
40784078
*connectionstyle* can be a string with connectionstyle name with
40794079
optional comma-separated attributes. Alternatively, the attrs can be
4080-
probided as keywords.
4080+
provided as keywords.
40814081
40824082
set_connectionstyle("arc,angleA=0,armA=30,rad=10")
40834083
set_connectionstyle("arc", angleA=0,armA=30,rad=10)

lib/matplotlib/tests/test_text.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ def test_text_with_arrow_annotation_get_window_extent():
382382
# bounding box of annotation (text + arrow)
383383
bbox = ann.get_window_extent(renderer=renderer)
384384
# bounding box of arrow
385-
arrow_bbox = ann.arrow.get_window_extent(renderer)
385+
arrow_bbox = ann.arrow_patch.get_window_extent(renderer)
386386
# bounding box of annotation text
387387
ann_txt_bbox = Text.get_window_extent(ann)
388388

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

401401
@cleanup
402402
def test_arrow_annotation_get_window_extent():
403-
figure = Figure(dpi=100)
403+
dpi = 100
404+
dots_per_point = dpi / 72
405+
figure = Figure(dpi=dpi)
404406
figure.set_figwidth(2.0)
405407
figure.set_figheight(2.0)
406408
renderer = RendererAgg(200, 200, 100)
407409

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

419421
eq_(bbox.width, 50.0)
420-
assert_almost_equal(bbox.height, 10.0 / 0.72)
422+
assert_almost_equal(bbox.height, 10.0 * dots_per_point)
421423
eq_(points[0, 0], 0.0)
422-
eq_(points[0, 1], 50.0 - 5 / 0.72)
424+
eq_(points[0, 1], 50.0 - 5 * dots_per_point)
423425

424426

425427
@cleanup

0 commit comments

Comments
 (0)
0