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

Skip to content

Commit 7b2a3ec

Browse files
committed
add ArrowStyle |-|
svn path=/trunk/matplotlib/; revision=8023
1 parent 18d19b7 commit 7b2a3ec

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

examples/pylab_examples/fancyarrow_demo.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
styles = mpatches.ArrowStyle.get_styles()
55

66
ncol=2
7-
nrow = len(styles) // ncol + 1
7+
nrow = (len(styles)+1) // ncol
88
figheight = (nrow+0.5)
99
fig1 = plt.figure(1, (4.*ncol/1.5, figheight/1.5))
1010
fontsize = 0.2 * 70
@@ -15,13 +15,19 @@
1515
ax.set_xlim(0, 4*ncol)
1616
ax.set_ylim(0, figheight)
1717

18+
def to_texstring(s):
19+
s = s.replace("<", r"$<$")
20+
s = s.replace(">", r"$>$")
21+
s = s.replace("|", r"$|$")
22+
return s
23+
1824
for i, (stylename, styleclass) in enumerate(sorted(styles.items())):
1925
x = 3.2 + (i//nrow)*4
2026
y = (figheight - 0.7 - i%nrow) # /figheight
2127
p = mpatches.Circle((x, y), 0.2, fc="w")
2228
ax.add_patch(p)
2329

24-
ax.annotate(stylename, (x, y),
30+
ax.annotate(to_texstring(stylename), (x, y),
2531
(x-1.2, y),
2632
#xycoords="figure fraction", textcoords="figure fraction",
2733
ha="right", va="center",

lib/matplotlib/patches.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,6 +3299,41 @@ def __init__(self, widthB=1., lengthB=0.2, angleB=None):
32993299
_style_list["-["] = BracketB
33003300

33013301

3302+
class BarAB(_Bracket):
3303+
"""
3304+
An arrow with a bracket(]) at both ends.
3305+
"""
3306+
3307+
def __init__(self,
3308+
widthA=1., angleA=None,
3309+
widthB=1., angleB=None):
3310+
"""
3311+
*widthA*
3312+
width of the bracket
3313+
3314+
*lengthA*
3315+
length of the bracket
3316+
3317+
*angleA*
3318+
angle between the bracket and the line
3319+
3320+
*widthB*
3321+
width of the bracket
3322+
3323+
*lengthB*
3324+
length of the bracket
3325+
3326+
*angleB*
3327+
angle between the bracket and the line
3328+
"""
3329+
3330+
super(ArrowStyle.BarAB, self).__init__(True, True, \
3331+
widthA=widthA, lengthA=0, angleA=angleA,
3332+
widthB=widthB, lengthB=0, angleB=angleB)
3333+
3334+
_style_list["|-|"] = BarAB
3335+
3336+
33023337
class Simple(_Base):
33033338
"""
33043339
A simple arrow. Only works with a quadratic bezier curve.

0 commit comments

Comments
 (0)