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

Skip to content

Addresses issue #24618 "Road sign" boxstyle/annotation #24697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
56 changes: 41 additions & 15 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2372,14 +2372,19 @@ def __call__(self, x0, y0, width, height, mutation_size):
class LArrow:
"""A box in the shape of a left-pointing arrow."""

def __init__(self, pad=0.3):
def __init__(self, pad=0.3, fhead=False):
"""
Parameters
----------
pad : float, default: 0.3
The amount of padding around the original box.

fhead : bool, default: False
If the arrowheads should be flush with the top
and botton sides of the arrow body.
"""
self.pad = pad
self.fhead = fhead

def __call__(self, x0, y0, width, height, mutation_size):
# padding
Expand All @@ -2394,11 +2399,17 @@ def __call__(self, x0, y0, width, height, mutation_size):
dxx = dx / 2
x0 = x0 + pad / 1.4 # adjust by ~sqrt(2)

return Path._create_closed(
[(x0 + dxx, y0), (x1, y0), (x1, y1), (x0 + dxx, y1),
(x0 + dxx, y1 + dxx), (x0 - dx, y0 + dx),
(x0 + dxx, y0 - dxx), # arrow
(x0 + dxx, y0)])
if self.fhead:
return Path._create_closed([(x0 + dxx - pad, y0), (x1, y0),
(x1, y1), (x0 + dxx - pad, y1),
(x0 - dx - pad, y0 + dx),
(x0 + dxx - pad, y0)])

return Path._create_closed([(x0 + dxx, y0), (x1, y0), (x1, y1),
(x0 + dxx, y1), (x0 + dxx, y1 + dxx),
(x0 - dx, y0 + dx),
(x0 + dxx, y0 - dxx), # arrow
(x0 + dxx, y0), (x0 + dxx, y0)])

@_register_style(_style_list)
class RArrow(LArrow):
Expand All @@ -2415,14 +2426,19 @@ class DArrow:
"""A box in the shape of a two-way arrow."""
# Modified from LArrow to add a right arrow to the bbox.

def __init__(self, pad=0.3):
def __init__(self, pad=0.3, fhead=False):
"""
Parameters
----------
pad : float, default: 0.3
The amount of padding around the original box.

fhead : bool, default: False
If the arrowheads should be flush with the top
and botton sides of the arrow body.
"""
self.pad = pad
self.fhead = fhead

def __call__(self, x0, y0, width, height, mutation_size):
# padding
Expand All @@ -2438,14 +2454,24 @@ def __call__(self, x0, y0, width, height, mutation_size):
dxx = dx / 2
x0 = x0 + pad / 1.4 # adjust by ~sqrt(2)

return Path._create_closed([
(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)])
if self.fhead:
return Path._create_closed([(x0 + dxx - pad, y0),
(x1 + pad, y0),
(x1 + dx + dxx + pad, y0 + dx),
(x1 + pad, y1),
(x0 + dxx - pad, y1),
(x0 - dx - pad, y0 + dx),
(x0 + dxx - pad, y0)])

return Path._create_closed([(x0 + dxx, y0), (x1, y0),
(x1, y0 - dxx),
(x1 + dx + dxx, y0 + dx),
(x1, y1 + dxx), # right-arrow
(x1, y1), (x0 + dxx, y1),
(x0 + dxx, y1 + dxx),
(x0 - dx, y0 + dx),
(x0 + dxx, y0 - dxx), # left-arrow
(x0 + dxx, y0)])

@_register_style(_style_list)
class Round:
Expand Down
10 changes: 5 additions & 5 deletions tutorials/text/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@
# Class Name Attrs
# ========== ============== ==========================
# Circle ``circle`` pad=0.3
# DArrow ``darrow`` pad=0.3
# DArrow ``darrow`` pad=0.3,fhead=False
# Ellipse ``ellipse`` pad=0.3
# LArrow ``larrow`` pad=0.3
# RArrow ``rarrow`` pad=0.3
# LArrow ``larrow`` pad=0.3,fhead=False
# RArrow ``rarrow`` pad=0.3,fhead=False
# Round ``round`` pad=0.3,rounding_size=None
# Round4 ``round4`` pad=0.3,rounding_size=None
# Roundtooth ``roundtooth`` pad=0.3,tooth_size=None
Expand All @@ -215,12 +215,12 @@
# (facecolor, edgewidth, etc.) can be accessed and modified as usual.
# `.FancyBboxPatch.set_boxstyle` sets the box shape::
#
# bb.set_boxstyle("rarrow", pad=0.6)
# bb.set_boxstyle("rarrow", pad=0.6, fhead=True)
#
# The attribute arguments can also be specified within the style
# name with separating comma::
#
# bb.set_boxstyle("rarrow, pad=0.6")
# bb.set_boxstyle("rarrow, pad=0.6, fhead=True")
#
#
# Defining custom box styles
Expand Down