Skip to content

Commit

Permalink
Merge pull request #3194 from lkilcher/annotate_bbox_DArrow
Browse files Browse the repository at this point in the history
Annotate bbox darrow
  • Loading branch information
tacaswell committed Jul 24, 2014
2 parents 1a87326 + 8e6aff2 commit 9e9a3cd
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/users/annotations_guide.rst
Expand Up @@ -46,6 +46,8 @@ keyword arguments. Currently, following box styles are implemented.
========== ============== ==========================
Class Name Attrs
========== ============== ==========================
Circle ``circle`` pad=0.3
DArrow ``darrow`` pad=0.3
LArrow ``larrow`` pad=0.3
RArrow ``rarrow`` pad=0.3
Round ``round`` pad=0.3,rounding_size=None
Expand Down
7 changes: 4 additions & 3 deletions examples/pylab_examples/fancybox_demo2.py
Expand Up @@ -2,13 +2,14 @@
import matplotlib.pyplot as plt

styles = mpatch.BoxStyle.get_styles()
spacing = 1.2

figheight = (len(styles)+.5)
figheight = (spacing * len(styles) + .5)
fig1 = plt.figure(1, (4/1.5, figheight/1.5))
fontsize = 0.3 * 72

for i, (stylename, styleclass) in enumerate(styles.items()):
fig1.text(0.5, (float(len(styles)) - 0.5 - i)/figheight, stylename,
for i, stylename in enumerate(sorted(styles.keys())):
fig1.text(0.5, (spacing * (float(len(styles)) - i) - 0.5)/figheight, stylename,
ha="center",
size=fontsize,
transform=fig1.transFigure,
Expand Down
51 changes: 51 additions & 0 deletions lib/matplotlib/patches.py
Expand Up @@ -2003,6 +2003,57 @@ def transmute(self, x0, y0, width, height, mutation_size):

_style_list["rarrow"] = RArrow

class DArrow(_Base):
"""
(Double) Arrow Box
"""
# This source is copied from LArrow,
# modified to add a right arrow to the bbox.

def __init__(self, pad=0.3):
self.pad = pad
super(BoxStyle.DArrow, self).__init__()

def transmute(self, x0, y0, width, height, mutation_size):

# padding
pad = mutation_size * self.pad

# width and height with padding added.
# The width is padded by the arrows, so we don't need to pad it.
height = height + 2. * pad

# boundary of the padded box
x0, y0 = x0 - pad, y0 - pad
x1, y1 = x0 + width, y0 + height

dx = (y1 - y0)/2.
dxx = dx * .5
# adjust x0. 1.4 <- sqrt(2)
x0 = x0 + pad / 1.4

cp = [(x0 + dxx, y0), (x1, y0), # bot-segment
(x1, y0 - dxx), (x1 + dx + dxx, y0 + dx),
(x1, y1 + dxx), # right-arrow
(x1, y1), (x0 + dxx, y1), # top-segment
(x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx),
(x0 + dxx, y0 - dxx), # left-arrow
(x0 + dxx, y0), (x0 + dxx, y0)] # close-poly

com = [Path.MOVETO, Path.LINETO,
Path.LINETO, Path.LINETO,
Path.LINETO,
Path.LINETO, Path.LINETO,
Path.LINETO, Path.LINETO,
Path.LINETO,
Path.LINETO, Path.CLOSEPOLY]

path = Path(cp, com)

return path

_style_list['darrow'] = DArrow

class Round(_Base):
"""
A box with round corners.
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_arrow_patches.py
Expand Up @@ -30,6 +30,27 @@ def test_fancyarrow():
ax.tick_params(labelleft=False, labelbottom=False)


@image_comparison(baseline_images=['boxarrow_test_image'], extensions=['png'])
def test_boxarrow():

styles = matplotlib.patches.BoxStyle.get_styles()

n = len(styles)
spacing = 1.2

figheight = (n * spacing + .5)
fig1 = plt.figure(1, figsize=(4 / 1.5, figheight / 1.5))

fontsize = 0.3 * 72

for i, stylename in enumerate(sorted(styles.keys())):
fig1.text(0.5, ((n - i) * spacing - 0.5)/figheight, stylename,
ha="center",
size=fontsize,
transform=fig1.transFigure,
bbox=dict(boxstyle=stylename, fc="w", ec="k"))


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit 9e9a3cd

Please sign in to comment.