Skip to content

Commit 3ff569e

Browse files
committed
Implement angles for bracket arrow styles.
1 parent 92b4bc3 commit 3ff569e

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lib/matplotlib/patches.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,7 @@ def __init__(self, bracketA=None, bracketB=None,
32073207
self.scaleA, self.scaleB = scaleA, scaleB
32083208

32093209
def _get_bracket(self, x0, y0,
3210-
cos_t, sin_t, width, length):
3210+
cos_t, sin_t, width, length, angle):
32113211

32123212
# arrow from x0, y0 to x1, y1
32133213
from matplotlib.bezier import get_normal_points
@@ -3224,6 +3224,10 @@ def _get_bracket(self, x0, y0,
32243224
Path.LINETO,
32253225
Path.LINETO]
32263226

3227+
if angle is not None:
3228+
trans = transforms.Affine2D().rotate_deg_around(x0, y0, angle)
3229+
vertices_arrow = trans.transform(vertices_arrow)
3230+
32273231
return vertices_arrow, codes_arrow
32283232

32293233
def transmute(self, path, mutation_size, linewidth):
@@ -3246,7 +3250,8 @@ def transmute(self, path, mutation_size, linewidth):
32463250
cos_t, sin_t = get_cos_sin(x1, y1, x0, y0)
32473251
verticesA, codesA = self._get_bracket(x0, y0, cos_t, sin_t,
32483252
self.widthA * scaleA,
3249-
self.lengthA * scaleA)
3253+
self.lengthA * scaleA,
3254+
self.angleA)
32503255
vertices_list.append(verticesA)
32513256
codes_list.append(codesA)
32523257

@@ -3259,7 +3264,8 @@ def transmute(self, path, mutation_size, linewidth):
32593264
cos_t, sin_t = get_cos_sin(x1, y1, x0, y0)
32603265
verticesB, codesB = self._get_bracket(x0, y0, cos_t, sin_t,
32613266
self.widthB * scaleB,
3262-
self.lengthB * scaleB)
3267+
self.lengthB * scaleB,
3268+
self.angleB)
32633269
vertices_list.append(verticesB)
32643270
codes_list.append(codesB)
32653271

13.5 KB
Loading

lib/matplotlib/tests/test_arrow_patches.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,31 @@ def test_arrow_styles():
119119
styles = mpatches.ArrowStyle.get_styles()
120120

121121
n = len(styles)
122-
fig, ax = plt.subplots(figsize=(6, 10))
122+
fig, ax = plt.subplots(figsize=(8, 8))
123123
ax.set_xlim(0, 1)
124124
ax.set_ylim(-1, n)
125+
fig.subplots_adjust(left=0, right=1, bottom=0, top=1)
125126

126127
for i, stylename in enumerate(sorted(styles)):
127-
patch = mpatches.FancyArrowPatch((0.1, i), (0.8, i),
128+
patch = mpatches.FancyArrowPatch((0.1, i), (0.45, i),
128129
arrowstyle=stylename,
129130
mutation_scale=25)
130131
ax.add_patch(patch)
131132

133+
for i, stylename in enumerate([']-[', ']-', '-[', '|-|']):
134+
style = stylename
135+
if stylename[0] != '-':
136+
style += ',angleA=ANGLE'
137+
if stylename[-1] != '-':
138+
style += ',angleB=ANGLE'
139+
140+
for j, angle in enumerate([-30, 60]):
141+
arrowstyle = style.replace('ANGLE', str(angle))
142+
patch = mpatches.FancyArrowPatch((0.55, 2*i + j), (0.9, 2*i + j),
143+
arrowstyle=arrowstyle,
144+
mutation_scale=25)
145+
ax.add_patch(patch)
146+
132147

133148
@image_comparison(['connection_styles.png'], style='mpl20', remove_text=True)
134149
def test_connection_styles():

0 commit comments

Comments
 (0)