8000 Annotate: draw text before arrow; closes #4140 · matplotlib/matplotlib@e7f3fb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7f3fb7

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

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
@@ -2596,14 +2596,14 @@ class ConnectionStyle(_Style):
25962596

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

26022602
connect(posA, posB)
26032603

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

@@ -2687,7 +2687,7 @@ def __call__(self, posA, posB,
26872687
return shrinked_path
26882688

26892689
def __reduce__(self):
2690-
# because we have decided to nest thes classes, we need to
2690+
# because we have decided to nest these classes, we need to
26912691
# add some more information to allow instance pickling.
26922692
import matplotlib.cbook as cbook
26932693
return (cbook._NestedClassGetter(),
@@ -2932,7 +2932,7 @@ def connect(self, posA, posB):
29322932
class Bar(_Base):
29332933
"""
29342934
A line with *angle* between A and B with *armA* and
2935-
*armB*. One of the arm is extend so that they are connected in
2935+
*armB*. One of the arms is extended so that they are connected in
29362936
a right angle. The length of armA is determined by (*armA*
29372937
+ *fraction* x AB distance). Same for armB.
29382938
"""
@@ -3906,7 +3906,7 @@ def __init__(self, posA=None, posB=None,
39063906
"""
39073907
If *posA* and *posB* is given, a path connecting two point are
39083908
created according to the connectionstyle. The path will be
3909-
clipped with *patchA* and *patchB* and further shirnked by
3909+
clipped with *patchA* and *patchB* and further shrinked by
39103910
*shrinkA* and *shrinkB*. An arrow is drawn along this
39113911
resulting path using the *arrowstyle* parameter. If *path*
39123912
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
@@ -296,7 +296,7 @@ def update_from(self, other):
296296
def _get_layout(self, renderer):
297297
"""
298298
return the extent (bbox) of the text together with
299-
multile-alignment information. Note that it returns a extent
299+
multiple-alignment information. Note that it returns an extent
300300
of a rotated text when necessary.
301301
"""
302302
key = self.get_prop_tup()
@@ -458,6 +458,9 @@ def set_bbox(self, rectprops):
458458

459459
if rectprops is not None:
460460
props = rectprops.copy()
461+
# Dump the pad kwarg; we still need to figure out how to
462+
# use it to expand the box, for backwards compatibility.
463+
pad = props.pop('pad', 4) # noqa
461464
boxstyle = props.pop("boxstyle", "square")
462465
bbox_transmuter = props.pop("bbox_transmuter", None)
463466

@@ -814,7 +817,7 @@ def set_backgroundcolor(self, color):
814817
ACCEPTS: any matplotlib color
815818
"""
816819
if self._bbox_patch is None:
817-
self.set_bbox = dict(facecolor=color, edgecolor=color)
820+
self.set_bbox(dict(facecolor=color, edgecolor=color))
818821
else:
819822
self._bbox_patch.update(dict(facecolor=color))
820823

@@ -2065,6 +2068,10 @@ def draw(self, renderer):
20652068
self._update_position_xytext(renderer, xy_pixel)
20662069
self.update_bbox_position_size(renderer)
20672070

2071+
# Draw text, including FancyBboxPatch, before FancyArrowPatch.
2072+
# Otherwise, the transform of the former Patch will be incomplete.
2073+
Text.draw(self, renderer)
2074+
20682075
if self.arrow is not None:
20692076
if self.arrow.figure is None and self.figure is not None:
20702077
self.arrow.figure = self.figure
@@ -2075,8 +2082,6 @@ def draw(self, renderer):
20752082
self.arrow_patch.figure = self.figure
20762083
self.arrow_patch.draw(renderer)
20772084

2078-
Text.draw(self, renderer)
2079-
20802085
def get_window_extent(self, renderer=None):
20812086
'''
20822087
Return a :class:`~matplotlib.transforms.Bbox` object bounding

0 commit comments

Comments
 (0)
2A62
0