8000 Merge pull request #20105 from anntzer/arrowstyledoc · matplotlib/matplotlib@e1d1095 · GitHub
[go: up one dir, main page]

Skip to content

Commit e1d1095

Browse files
authored
Merge pull request #20105 from anntzer/arrowstyledoc
Shorten Curve arrowstyle implementations.
2 parents df667ba + 006c29b commit e1d1095

File tree

1 file changed

+21
-94
lines changed

1 file changed

+21
-94
lines changed

lib/matplotlib/patches.py

Lines changed: 21 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,24 +3226,24 @@ def __call__(self, path, mutation_size, linewidth,
32263226
class _Curve(_Base):
32273227
"""
32283228
A simple arrow which will work with any path instance. The
3229-
returned path is simply concatenation of the original path + at
3229+
returned path is the concatenation of the original path, and at
32303230
most two paths representing the arrow head at the begin point and the
32313231
at the end point. The arrow heads can be either open or closed.
32323232
"""
32333233

3234-
def __init__(self, beginarrow=None, endarrow=None,
3235-
fillbegin=False, fillend=False,
3236-
head_length=.2, head_width=.1):
3234+
beginarrow = endarrow = False # Whether arrows are drawn.
3235+
fillbegin = fillend = False # Whether arrows are filled.
3236+
3237+
def __init__(self, head_length=.4, head_width=.2):
32373238
"""
3238-
The arrows are drawn if *beginarrow* and/or *endarrow* are
3239-
true. *head_length* and *head_width* determines the size
3240-
of the arrow relative to the *mutation scale*. The
3241-
arrowhead at the begin (or end) is closed if fillbegin (or
3242-
fillend) is True.
3239+
Parameters
3240+
----------
3241+
head_length : float, default: 0.4
3242+
Length of the arrow head, relative to *mutation_scale*.
3243+
head_width : float, default: 0.2
3244+
Width of the arrow head, relative to *mutation_scale*.
32433245
"""
3244-
self.beginarrow, self.endarrow = beginarrow, endarrow
32453246
self.head_length, self.head_width = head_length, head_width
3246-
self.fillbegin, self.fillend = fillbegin, fillend
32473247
super().__init__()
32483248

32493249
def _get_arrow_wedge(self, x0, y0, x1, y1,
@@ -3357,113 +3357,40 @@ def transmute(self, path, mutation_size, linewidth):
33573357
class Curve(_Curve):
33583358
"""A simple curve without any arrow head."""
33593359

3360-
def __init__(self):
3361-
super().__init__(beginarrow=False, endarrow=False)
3360+
def __init__(self): # hide head_length, head_width
3361+
# These attributes (whose values come from backcompat) only matter
3362+
# if someone modifies beginarrow/etc. on an ArrowStyle instance.
3363+
super().__init__(head_length=.2, head_width=.1)
33623364

33633365
@_register_style(_style_list, name="<-")
33643366
class CurveA(_Curve):
33653367
"""An arrow with a head at its begin point."""
3366-
3367-
def __init__(self, head_length=.4, head_width=.2):
3368-
"""
3369-
Parameters
3370-
----------
3371-
head_length : float, default: 0.4
3372-
Length of the arrow head.
3373-
3374-
head_width : float, default: 0.2
3375-
Width of the arrow head.
3376-
"""
3377-
super().__init__(beginarrow=True, endarrow=False,
3378-
head_length=head_length, head_width=head_width)
3368+
beginarrow = True
33793369

33803370
@_register_style(_style_list, name="->")
33813371
class CurveB(_Curve):
33823372
"""An arrow with a head at its end point."""
3383-
3384-
def __init__(self, head_length=.4, head_width=.2):
3385-
"""
3386-
Parameters
3387-
----------
3388-
head_length : float, default: 0.4
3389-
Length of the arrow head.
3390-
3391-
head_width : float, default: 0.2
3392-
Width of the arrow head.
3393-
"""
3394-
super().__init__(beginarrow=False, endarrow=True,
3395-
head_length=head_length, head_width=head_width)
3373+
endarrow = True
33963374

33973375
@_register_style(_style_list, name="<->")
33983376
class CurveAB(_Curve):
33993377
"""An arrow with heads both at the begin and the end point."""
3400-
3401-
def __init__(self, head_length=.4, head_width=.2):
3402-
"""
3403-
Parameters
3404-
----------
3405-
head_length : float, default: 0.4
3406-
Length of the arrow head.
3407-
3408-
head_width : float, default: 0.2
3409-
Width of the arrow head.
3410-
"""
3411-
super().__init__(beginarrow=True, endarrow=True,
3412-
head_length=head_length, head_width=head_width)
3378+
beginarrow = endarrow = True
34133379

34143380
@_register_style(_style_list, name="<|-")
34153381
class CurveFilledA(_Curve):
34163382
"""An arrow with filled triangle head at the begin."""
3417-
3418-
def __init__(self, head_length=.4, head_width=.2):
3419-
"""
3420-
Parameters
3421-
----------
3422-
head_length : float, default: 0.4
3423-
Length of the arrow head.
3424-
3425-
head_width : float, default: 0.2
3426-
Width of the arrow head.
3427-
"""
3428-
super().__init__(beginarrow=True, endarrow=False,
3429-
fillbegin=True, fillend=False,
3430-
head_length=head_length, head_width=head_width)
3383+
beginarrow = fillbegin = True
34313384

34323385
@_register_style(_style_list, name="-|>")
34333386
class CurveFilledB(_Curve):
34343387
"""An arrow with filled triangle head at the end."""
3435-
3436-
def __init__(self, head_length=.4, head_width=.2):
3437-
"""
3438-
Parameters
3439-
----------
3440-
head_length : float, default: 0.4
3441-
Length of the arrow head.
3442-
3443-
head_width : float, default: 0.2
3444-
Width of the arrow head.
3445-
"""
3446-
super().__init__(beginarrow=False, endarrow=True,
3447-
fillbegin=False, fillend=True,
3448-
head_length=head_length, head_width=head_width)
3388+
endarrow = fillend = True
34493389

34503390
@_register_style(_style_list, name="<|-|>")
34513391
class CurveFilledAB(_Curve):
34523392
"""An arrow with filled triangle heads at both ends."""
3453-
3454-
def __init__(self, head_length=.4, head_wid 9505 th=.2):
3455-
"""
3456-
Parameters
3457-
----------
3458-
head_length : float, default: 0.4
3459-
Length of the arrow head.
3460-
3461-
head_width : float, default: 0.2
3462-
Width of the arrow head.
3463-
"""
3464-
super().__init__(beginarrow=True, endarrow=True,
3465-
fillbegin=True, fillend=True,
3466-
head_length=head_length, head_width=head_width)
3393+
beginarrow = endarrow = fillbegin = fillend = True
34673394

34683395
class _Bracket(_Base):
34693396

0 commit comments

Comments
 (0)
0