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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ def tk_window_focus():
'matplotlib.tests.test_tightlayout',
'matplotlib.tests.test_triangulation',
'matplotlib.tests.test_transforms',
'matplotlib.tests.test_arrow_patches',
]


Expand Down
90 changes: 61 additions & 29 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,18 @@ def connect(self, posA, posB):
{"AvailableConnectorstyles": _pprint_styles(_style_list)}


def _point_along_a_line(x0, y0, x1, y1, d):
"""
find a point along a line connecting (x0, y0) -- (x1, y1) whose
distance from (x0, y0) is d.
"""
dx, dy = x0 - x1, y0 - y1
ff = d/(dx*dx+dy*dy)**.5
x2, y2 = x0 - ff*dx, y0 - ff*dy

return x2, y2


class ArrowStyle(_Style):
"""
:class:`ArrowStyle` is a container class which defines several
Expand Down Expand Up @@ -3460,35 +3472,57 @@ def transmute(self, path, mutation_size, linewidth):
head_length = self.head_length * mutation_size
in_f = inside_circle(x2, y2, head_length)
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
arrow_out, arrow_in = \
split_bezier_intersecting_with_closedpath(arrow_path,
in_f,
tolerence=0.01)

from bezier import NonIntersectingPathException

try:
arrow_out, arrow_in = \
split_bezier_intersecting_with_closedpath(arrow_path,
in_f,
tolerence=0.01)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length long.
x0, y0 = _point_along_a_line(x2, y2, x1, y1, head_length)
x1n, y1n = 0.5*(x0+x2), 0.5*(y0+y2)
arrow_in = [(x0, y0), (x1n, y1n), (x2, y2)]
arrow_out = None

# head
head_width = self.head_width * mutation_size
head_l, head_r = make_wedged_bezier2(arrow_in, head_width / 2.,
wm=.5)
head_left, head_right = \
make_wedged_bezier2(arrow_in, head_width/2.,
wm=.5)


# tail
tail_width = self.tail_width * mutation_size
tail_left, tail_right = get_parallels(arrow_out, tail_width / 2.)
if arrow_out is not None:
tail_width = self.tail_width * mutation_size
tail_left, tail_right = get_parallels(arrow_out, tail_width/2.)

#head_right, head_left = head_r, head_l
patch_path = [(Path.MOVETO, tail_right[0]),
(Path.CURVE3, tail_right[1]),
(Path.CURVE3, tail_right[2]),
(Path.LINETO, head_right[0]),
(Path.CURVE3, head_right[1]),
(Path.CURVE3, head_right[2]),
(Path.CURVE3, head_left[1]),
(Path.CURVE3, head_left[0]),
(Path.LINETO, tail_left[2]),
(Path.CURVE3, tail_left[1]),
(Path.CURVE3, tail_left[0]),
(Path.LINETO, tail_right[0]),
(Path.CLOSEPOLY, tail_right[0]),
]
else:
patch_path = [(Path.MOVETO, head_right[0]),
(Path.CURVE3, head_right[1]),
(Path.CURVE3, head_right[2]),
(Path.CURVE3, head_left[1]),
(Path.CURVE3, head_left[0]),
(Path.CLOSEPOLY, head_left[0]),
]

head_right, head_left = head_r, head_l
patch_path = [(Path.MOVETO, tail_right[0]),
(Path.CURVE3, tail_right[1]),
(Path.CURVE3, tail_right[2]),
(Path.LINETO, head_right[0]),
(Path.CURVE3, head_right[1]),
(Path.CURVE3, head_right[2]),
(Path.CURVE3, head_left[1]),
(Path.CURVE3, head_left[0]),
(Path.LINETO, tail_left[2]),
(Path.CURVE3, tail_left[1]),
(Path.CURVE3, tail_left[0]),
(Path.LINETO, tail_right[0]),
(Path.CLOSEPOLY, tail_right[0]),
]
path = Path([p for c, p in patch_path], [c for c, p in patch_path])

return path, True
Expand Down Expand Up @@ -3536,12 +3570,10 @@ def transmute(self, path, mutation_size, linewidth):
in_f,
tolerence=0.01)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length
# long.
dx, dy = x2 - x1, y2 - y1
ff = head_length / (dx * dx + dy * dy) ** .5
x0, y0 = x2 - ff * dx, y2 - ff * dy
arrow_path = [(x0, y0), (x1, y1), (x2, y2)]
# if this happens, make a straight line of the head_length long.
x0, y0 = _point_along_a_line(x2, y2, x1, y1, head_length)
x1n, y1n = 0.5*(x0+x2), 0.5*(y0+y2)
arrow_path = [(x0, y0), (x1n, y1n), (x2, y2)]
path_head = arrow_path
else:
path_head = path_in
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading