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

Skip to content

Commit 1aa2e58

Browse files
committed
Added 'double arrow' (DArrow) to patches.BoxStyle.
1 parent 0287479 commit 1aa2e58

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

doc/users/annotations_guide.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ keyword arguments. Currently, following box styles are implemented.
4848
========== ============== ==========================
4949
LArrow ``larrow`` pad=0.3
5050
RArrow ``rarrow`` pad=0.3
51+
DArrow ``darrow`` pad=0.3
5152
Round ``round`` pad=0.3,rounding_size=None
5253
Round4 ``round4`` pad=0.3,rounding_size=None
5354
Roundtooth ``roundtooth`` pad=0.3,tooth_size=None

lib/matplotlib/patches.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,57 @@ def transmute(self, x0, y0, width, height, mutation_size):
20032003

20042004
_style_list["rarrow"] = RArrow
20052005

2006+
class DArrow(_Base):
2007+
"""
2008+
(Double) Arrow Box
2009+
"""
2010+
# This source is copied from LArrow,
2011+
# modified to add a right arrow to the bbox.
2012+
2013+
def __init__(self, pad=0.3):
2014+
self.pad = pad
2015+
super(BoxStyle.DArrow, self).__init__()
2016+
2017+
def transmute(self, x0, y0, width, height, mutation_size):
2018+
2019+
# padding
2020+
pad = mutation_size * self.pad
2021+
2022+
# width and height with padding added.
2023+
# The width is padded by the arrows, so we don't need to pad it.
2024+
height = height + 2. * pad
2025+
2026+
# boundary of the padded box
2027+
x0, y0 = x0 - pad, y0 - pad
2028+
x1, y1 = x0 + width, y0 + height
2029+
2030+
dx = (y1 - y0)/2.
2031+
dxx = dx * .5
2032+
# adjust x0. 1.4 <- sqrt(2)
2033+
x0 = x0 + pad / 1.4
2034+
2035+
cp = [(x0 + dxx, y0), (x1, y0), # bot-segment
2036+
(x1, y0 - dxx), (x1 + dx + dxx, y0 + dx),
2037+
(x1, y1 + dxx), # right-arrow
2038+
(x1, y1), (x0 + dxx, y1), # top-segment
2039+
(x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx),
2040+
(x0 + dxx, y0 - dxx), # left-arrow
2041+
(x0 + dxx, y0), (x0 + dxx, y0)] # close-poly
2042+
2043+
com = [Path.MOVETO, Path.LINETO,
2044+
Path.LINETO, Path.LINETO,
2045+
Path.LINETO,
2046+
Path.LINETO, Path.LINETO,
2047+
Path.LINETO, Path.LINETO,
2048+
Path.LINETO,
2049+
Path.LINETO, Path.CLOSEPOLY]
2050+
2051+
path = Path(cp, com)
2052+
2053+
return path
2054+
2055+
_style_list['darrow'] = DArrow
2056+
20062057
class Round(_Base):
20072058
"""
20082059
A box with round corners.

0 commit comments

Comments
 (0)