Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7829262

Browse files
committed
Annotate: draw text before arrow; closes #4140
Some comment and docstring typos are also fixed.
1 parent 9d933bc commit 7829262

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/matplotlib/patches.py

Lines changed: 7 additions & 7 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

@@ -2749,7 +2749,7 @@ def __call__(self, posA, posB,
27492749
return shrinked_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
"""
@@ -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 shrinked 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*,

lib/matplotlib/text.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def update_from(self, other):
319319
def _get_layout(self, renderer):
320320
"""
321321
return the extent (bbox) of the text together with
322-
multile-alignment information. Note that it returns a extent
322+
multiple-alignment information. Note that it returns an extent
323323
of a rotated text when necessary.
324324
"""
325325
key = self.get_prop_tup()
@@ -481,6 +481,9 @@ def set_bbox(self, rectprops):
481481

482482
if rectprops is not None:
483483
props = rectprops.copy()
484+
# Dump the pad kwarg; we still need to figure out how to
485+
# use it to expand the box, for backwards compatibility.
486+
pad = props.pop('pad', 4) # noqa
484487
boxstyle = props.pop("boxstyle", "square")
485488
bbox_transmuter = props.pop("bbox_transmuter", None)
486489

@@ -948,7 +951,7 @@ def set_backgroundcolor(self, color):
948951
ACCEPTS: any matplotlib color
949952
"""
950953
if self._bbox_patch is None:
951-
self.set_bbox = dict(facecolor=color, edgecolor=color)
954+
self.set_bbox(dict(facecolor=color, edgecolor=color))
952955
else:
953956
self._bbox_patch.update(dict(facecolor=color))
954957

@@ -2227,6 +2230,10 @@ def draw(self, renderer):
22272230
self._update_position_xytext(renderer, xy_pixel)
22282231
self.update_bbox_position_size(renderer)
22292232

2233+
# Draw text, including FancyBboxPatch, before FancyArrowPatch.
2234+
# Otherwise, the transform of the former Patch will be incomplete.
2235+
Text.draw(self, renderer)
2236+
22302237
if self.arrow is not None:
22312238
if self.arrow.figure is None and self.figure is not None:
22322239
self.arrow.figure = self.figure
@@ -2237,8 +2244,6 @@ def draw(self, renderer):
22372244
self.arrow_patch.figure = self.figure
22382245
self.arrow_patch.draw(renderer)
22392246

2240-
Text.draw(self, renderer)
2241-
22422247
def get_window_extent(self, renderer=None):
22432248
'''
22442249
Return a :class:`~matplotlib.transforms.Bbox` object bounding

0 commit comments

Comments
 (0)