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

Skip to content

Commit 006c29b

Browse files
committed
Shorten Curve arrowstyle implementations.
... by moving {begin,end}arrow and fill{begin,end} to class attributes.
1 parent d45060c commit 006c29b

1 file changed

Lines changed: 21 additions & 94 deletions

File tree

lib/matplotlib/patches.py

Lines changed: 21 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,24 +2971,24 @@ def __call__(self, path, mutation_size, linewidth,
29712971
class _Curve(_Base):
29722972
"""
29732973
A simple arrow which will work with any path instance. The
2974-
returned path is simply concatenation of the original path + at
2974+
returned path is the concatenation of the original path, and at
29752975
most two paths representing the arrow head at the begin point and the
29762976
at the end point. The arrow heads can be either open or closed.
29772977
"""
29782978

2979-
def __init__(self, beginarrow=None, endarrow=None,
2980-
fillbegin=False, fillend=False,
2981-
head_length=.2, head_width=.1):
2979+
beginarrow = endarrow = False # Whether arrows are drawn.
2980+
fillbegin = fillend = False # Whether arrows are filled.
2981+
2982+
def __init__(self, head_length=.4, head_width=.2):
29822983
"""
2983-
The arrows are drawn if *beginarrow* and/or *endarrow* are
2984-
true. *head_length* and *head_width* determines the size
2985-
of the arrow relative to the *mutation scale*. The
2986-
arrowhead at the begin (or end) is closed if fillbegin (or
2987-
fillend) is True.
2984+
Parameters
2985+
----------
2986+
head_length : float, default: 0.4
2987+
Length of the arrow head, relative to *mutation_scale*.
2988+
head_width : float, default: 0.2
2989+
Width of the arrow head, relative to *mutation_scale*.
29882990
"""
2989-
self.beginarrow, self.endarrow = beginarrow, endarrow
29902991
self.head_length, self.head_width = head_length, head_width
2991-
self.fillbegin, self.fillend = fillbegin, fillend
29922992
super().__init__()
29932993

29942994
def _get_arrow_wedge(self, x0, y0, x1, y1,
@@ -3102,113 +3102,40 @@ def transmute(self, path, mutation_size, linewidth):
31023102
class Curve(_Curve):
31033103
"""A simple curve without any arrow head."""
31043104

3105-
def __init__(self):
3106-
super().__init__(beginarrow=False, endarrow=False)
3105+
def __init__(self): # hide head_length, head_width
3106+
# These attributes (whose values come from backcompat) only matter
3107+
# if someone modifies beginarrow/etc. on an ArrowStyle instance.
3108+
super().__init__(head_length=.2, head_width=.1)
31073109

31083110
@_register_style(_style_list, name="<-")
31093111
class CurveA(_Curve):
31103112
"""An arrow with a head at its begin point."""
3111-
3112-
def __init__(self, head_length=.4, head_width=.2):
3113-
"""
3114-
Parameters
3115-
----------
3116-
head_length : float, default: 0.4
3117-
Length of the arrow head.
3118-
3119-
head_width : float, default: 0.2
3120-
Width of the arrow head.
3121-
"""
3122-
super().__init__(beginarrow=True, endarrow=False,
3123-
head_length=head_length, head_width=head_width)
3113+
beginarrow = True
31243114

31253115
@_register_style(_style_list, name="->")
31263116
class CurveB(_Curve):
31273117
"""An arrow with a head at its end point."""
3128-
3129-
def __init__(self, head_length=.4, head_width=.2):
3130-
"""
3131-
Parameters
3132-
----------
3133-
head_length : float, default: 0.4
3134-
Length of the arrow head.
3135-
3136-
head_width : float, default: 0.2
3137-
Width of the arrow head.
3138-
"""
3139-
super().__init__(beginarrow=False, endarrow=True,
3140-
head_length=head_length, head_width=head_width)
3118+
endarrow = True
31413119

31423120
@_register_style(_style_list, name="<->")
31433121
class CurveAB(_Curve):
31443122
"""An arrow with heads both at the begin and the end point."""
3145-
3146-
def __init__(self, head_length=.4, head_width=.2):
3147-
"""
3148-
Parameters
3149-
----------
3150-
head_length : float, default: 0.4
3151-
Length of the arrow head.
3152-
3153-
head_width : float, default: 0.2
3154-
Width of the arrow head.
3155-
"""
3156-
super().__init__(beginarrow=True, endarrow=True,
3157-
head_length=head_length, head_width=head_width)
3123+
beginarrow = endarrow = True
31583124

31593125
@_register_style(_style_list, name="<|-")
31603126
class CurveFilledA(_Curve):
31613127
"""An arrow with filled triangle head at the begin."""
3162-
3163-
def __init__(self, head_length=.4, head_width=.2):
3164-
"""
3165-
Parameters
3166-
----------
3167-
head_length : float, default: 0.4
3168-
Length of the arrow head.
3169-
3170-
head_width : float, default: 0.2
3171-
Width of the arrow head.
3172-
"""
3173-
super().__init__(beginarrow=True, endarrow=False,
3174-
fillbegin=True, fillend=False,
3175-
head_length=head_length, head_width=head_width)
3128+
beginarrow = fillbegin = True
31763129

31773130
@_register_style(_style_list, name="-|>")
31783131
class CurveFilledB(_Curve):
31793132
"""An arrow with filled triangle head at the end."""
3180-
3181-
def __init__(self, head_length=.4, head_width=.2):
3182-
"""
3183-
Parameters
3184-
----------
3185-
head_length : float, default: 0.4
3186-
Length of the arrow head.
3187-
3188-
head_width : float, default: 0.2
3189-
Width of the arrow head.
3190-
"""
3191-
super().__init__(beginarrow=False, endarrow=True,
3192-
fillbegin=False, fillend=True,
3193-
head_length=head_length, head_width=head_width)
3133+
endarrow = fillend = True
31943134

31953135
@_register_style(_style_list, name="<|-|>")
31963136
class CurveFilledAB(_Curve):
31973137
"""An arrow with filled triangle heads at both ends."""
3198-
3199-
def __init__(self, head_length=.4, head_width=.2):
3200-
"""
3201-
Parameters
3202-
----------
3203-
head_length : float, default: 0.4
3204-
Length of the arrow head.
3205-
3206-
head_width : float, default: 0.2
3207-
Width of the arrow head.
3208-
"""
3209-
super().__init__(beginarrow=True, endarrow=True,
3210-
fillbegin=True, fillend=True,
3211-
head_length=head_length, head_width=head_width)
3138+
beginarrow = endarrow = fillbegin = fillend = True
32123139

32133140
class _Bracket(_Base):
32143141

0 commit comments

Comments
 (0)