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

Skip to content

Commit c5c5a5d

Browse files
authored
Merge pull request #8319 from dstansby/fancyarrow-doc
FancyArrowPatch docstring overhaul
2 parents d16c4a1 + ce10c39 commit c5c5a5d

File tree

1 file changed

+141
-71
lines changed

1 file changed

+141
-71
lines changed

lib/matplotlib/patches.py

Lines changed: 141 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ def transmute(self, path, mutation_size, linewidth):
39973997

39983998
class FancyArrowPatch(Patch):
39993999
"""
4000-
A fancy arrow patch. It draws an arrow using the :class:ArrowStyle.
4000+
A fancy arrow patch. It draws an arrow using the :class:`ArrowStyle`.
40014001
"""
40024002
_edge_default = True
40034003

@@ -4006,10 +4006,10 @@ def __str__(self):
40064006
if self._posA_posB is not None:
40074007
(x1, y1), (x2, y2) = self._posA_posB
40084008
return self.__class__.__name__ \
4009-
+ "(%g,%g->%g,%g)" % (x1, y1, x2, y2)
4009+
+ "(%g,%g->%g,%g)" % (x1, y1, x2, y2)
40104010
else:
40114011
return self.__class__.__name__ \
4012-
+ "(%s)" % (str(self._path_original),)
4012+
+ "(%s)" % (str(self._path_original),)
40134013

40144014
@docstring.dedent_interpd
40154015
def __init__(self, posA=None, posB=None,
@@ -4020,46 +4020,80 @@ def __init__(self, posA=None, posB=None,
40204020
connector=None,
40214021
patchA=None,
40224022
patchB=None,
4023-
shrinkA=2.,
4024-
shrinkB=2.,
4025-
mutation_scale=1.,
4023+
shrinkA=2,
4024+
shrinkB=2,
4025+
mutation_scale=1,
40264026
mutation_aspect=None,
4027-
dpi_cor=1.,
4027+
dpi_cor=1,
40284028
**kwargs):
40294029
"""
4030-
If *posA* and *posB* is given, a path connecting two point are
4031-
created according to the connectionstyle. The path will be
4030+
If *posA* and *posB* are given, a path connecting two points is
4031+
created according to *connectionstyle*. The path will be
40324032
clipped with *patchA* and *patchB* and further shrunken by
40334033
*shrinkA* and *shrinkB*. An arrow is drawn along this
4034-
resulting path using the *arrowstyle* parameter. If *path*
4035-
provided, an arrow is drawn along this path and *patchA*,
4036-
*patchB*, *shrinkA*, and *shrinkB* are ignored.
4034+
resulting path using the *arrowstyle* parameter.
40374035
4038-
The *connectionstyle* describes how *posA* and *posB* are
4039-
connected. It can be an instance of the ConnectionStyle class
4040-
(matplotlib.patches.ConnectionStlye) or a string of the
4041-
connectionstyle name, with optional comma-separated
4042-
attributes. The following connection styles are available.
4036+
Alternatively if *path* is provided, an arrow is drawn along this path
4037+
and *patchA*, *patchB*, *shrinkA*, and *shrinkB* are ignored.
40434038
4044-
%(AvailableConnectorstyles)s
4039+
Parameters
4040+
----------
40454041
4042+
posA, posB : None, tuple, optional (default: None)
4043+
(x,y) coordinates of arrow tail and arrow head respectively.
40464044
4047-
The *arrowstyle* describes how the fancy arrow will be
4048-
drawn. It can be string of the available arrowstyle names,
4049-
with optional comma-separated attributes, or one of the
4050-
ArrowStyle instance. The optional attributes are meant to be
4051-
scaled with the *mutation_scale*. The following arrow styles are
4052-
available.
4045+
path : None, Path (default: None)
4046+
:class:`matplotlib.path.Path` instance. If provided, an arrow is
4047+
drawn along this path and *patchA*, *patchB*, *shrinkA*, and
4048+
*shrinkB* are ignored.
40534049
4054-
%(AvailableArrowstyles)s
4050+
arrowstyle : str or ArrowStyle, optional (default: 'simple')
4051+
Describes how the fancy arrow will be
4052+
drawn. It can be string of the available arrowstyle names,
4053+
with optional comma-separated attributes, or an
4054+
:class:`ArrowStyle` instance. The optional attributes are meant to
4055+
be scaled with the *mutation_scale*. The following arrow styles are
4056+
available:
40554057
4056-
*mutation_scale* : a value with which attributes of arrowstyle
4057-
(e.g., head_length) will be scaled. default=1.
4058+
%(AvailableArrowstyles)s
40584059
4059-
*mutation_aspect* : The height of the rectangle will be
4060-
squeezed by this value before the mutation and the mutated
4061-
box will be stretched by the inverse of it. default=None.
4060+
arrow_transmuter :
4061+
Ignored
4062+
4063+
connectionstyle : str, ConnectionStyle, or None, optional
4064+
(default: 'arc3')
4065+
Describes how *posA* and *posB* are connected. It can be an
4066+
instance of the :class:`ConnectionStyle` class or a string of the
4067+
connectionstyle name, with optional comma-separated attributes. The
4068+
following connection styles are available:
4069+
4070+
%(AvailableConnectorstyles)s
40624071
4072+
connector :
4073+
Ignored
4074+
4075+
patchA, patchB : None, Patch, optional (default: None)
4076+
Head and tail patch respectively. :class:`matplotlib.patch.Patch`
4077+
instance.
4078+
4079+
shrinkA, shrinkB : scalar, optional (default: 2)
4080+
Shrinking factor of the tail and head of the arrow respectively
4081+
4082+
mutation_scale : scalar, optional (default: 1)
4083+
Value with which attributes of *arrowstyle* (e.g., *head_length*)
4084+
will be scaled.
4085+
4086+
mutation_aspect : None, scalar, optional (default: None)
4087+
The height of the rectangle will be squeezed by this value before
4088+
the mutation and the mutated box will be stretched by the inverse
4089+
of it.
4090+
4091+
dpi_cor : scalar, optional (defualt: 1)
4092+
dpi_cor is currently used for linewidth-related things and shrink
4093+
factor. Mutation scale is affected by this.
4094+
4095+
Notes
4096+
-----
40634097
Valid kwargs are:
40644098
%(Patch)s
40654099
"""
@@ -4091,28 +4125,39 @@ def __init__(self, posA=None, posB=None,
40914125
self._mutation_aspect = mutation_aspect
40924126

40934127
self.set_dpi_cor(dpi_cor)
4094-
#self._draw_in_display_coordinate = True
40954128

40964129
def set_dpi_cor(self, dpi_cor):
40974130
"""
40984131
dpi_cor is currently used for linewidth-related things and
40994132
shrink factor. Mutation scale is affected by this.
4100-
"""
41014133
4134+
Parameters
4135+
----------
4136+
dpi_cor : scalar
4137+
"""
41024138
self._dpi_cor = dpi_cor
41034139
self.stale = True
41044140

41054141
def get_dpi_cor(self):
41064142
"""
41074143
dpi_cor is currently used for linewidth-related things and
41084144
shrink factor. Mutation scale is affected by this.
4109-
"""
41104145
4146+
Returns
4147+
-------
4148+
dpi_cor : scalar
4149+
"""
41114150
return self._dpi_cor
41124151

41134152
def set_positions(self, posA, posB):
4114-
""" set the begin and end positions of the connecting
4115-
path. Use current value if None.
4153+
"""
4154+
Set the begin and end positions of the connecting path.
4155+
4156+
Parameters
4157+
----------
4158+
posA, posB : None, tuple
4159+
(x,y) coordinates of arrow tail and arrow head respectively. If
4160+
`None` use current value.
41164161
"""
41174162
if posA is not None:
41184163
self._posA_posB[0] = posA
@@ -4121,65 +4166,83 @@ def set_positions(self, posA, posB):
41214166
self.stale = True
41224167

41234168
def set_patchA(self, patchA):
4124-
""" set the begin patch.
4169+
"""
4170+
Set the tail patch.
4171+
4172+
Parameters
4173+
----------
4174+
patchA : Patch
4175+
:class:`matplotlib.patch.Patch` instance.
41254176
"""
41264177
self.patchA = patchA
41274178
self.stale = True
41284179

41294180
def set_patchB(self, patchB):
4130-
""" set the begin patch
4181+
"""
4182+
Set the head patch.
4183+
4184+
Parameters
4185+
----------
4186+
patchB : Patch
4187+
:class:`matplotlib.patch.Patch` instance.
41314188
"""
41324189
self.patchB = patchB
41334190
self.stale = True
41344191

41354192
def set_connectionstyle(self, connectionstyle, **kw):
41364193
"""
4137-
Set the connection style.
4194+
Set the connection style. Old attributes are forgotten.
4195+
4196+
Parameters
4197+
----------
4198+
connectionstyle : None, ConnectionStyle instance, or string
4199+
Can be a string with connectionstyle name with
4200+
optional comma-separated attributes, e.g.::
41384201
4139-
*connectionstyle* can be a string with connectionstyle name with
4140-
optional comma-separated attributes. Alternatively, the attrs can be
4141-
provided as keywords.
4202+
set_connectionstyle("arc,angleA=0,armA=30,rad=10")
41424203
4143-
set_connectionstyle("arc,angleA=0,armA=30,rad=10")
4144-
set_connectionstyle("arc", angleA=0,armA=30,rad=10)
4204+
Alternatively, the attributes can be provided as keywords, e.g.::
41454205
4146-
Old attrs simply are forgotten.
4206+
set_connectionstyle("arc", angleA=0,armA=30,rad=10)
41474207
4148-
Without argument (or with connectionstyle=None), return
4149-
available styles as a list of strings.
4208+
Without any arguments (or with ``connectionstyle=None``), return
4209+
available styles as a list of strings.
41504210
"""
41514211

41524212
if connectionstyle is None:
41534213
return ConnectionStyle.pprint_styles()
41544214

4155-
if (isinstance(connectionstyle, ConnectionStyle._Base)
4156-
or callable(connectionstyle)):
4215+
if (isinstance(connectionstyle, ConnectionStyle._Base) or
4216+
callable(connectionstyle)):
41574217
self._connector = connectionstyle
41584218
else:
41594219
self._connector = ConnectionStyle(connectionstyle, **kw)
41604220
self.stale = True
41614221

41624222
def get_connectionstyle(self):
41634223
"""
4164-
Return the ConnectionStyle instance
4224+
Return the :class:`ConnectionStyle` instance.
41654225
"""
41664226
return self._connector
41674227

41684228
def set_arrowstyle(self, arrowstyle=None, **kw):
41694229
"""
4170-
Set the arrow style.
4230+
Set the arrow style. Old attributes are forgotten. Without arguments
4231+
(or with ``arrowstyle=None``) returns available box styles as a list of
4232+
strings.
41714233
4172-
*arrowstyle* can be a string with arrowstyle name with optional
4173-
comma-separated attributes. Alternatively, the attrs can
4174-
be provided as keywords.
4234+
Parameters
4235+
----------
4236+
arrowstyle : None, ArrowStyle, str, optional (default: None)
4237+
Can be a string with arrowstyle name with optional comma-separated
4238+
attributes, e.g.::
41754239
4176-
set_arrowstyle("Fancy,head_length=0.2")
4177-
set_arrowstyle("fancy", head_length=0.2)
4240+
set_arrowstyle("Fancy,head_length=0.2")
41784241
4179-
Old attrs simply are forgotten.
4242+
Alternatively attributes can be provided as keywords, e.g.::
4243+
4244+
set_arrowstyle("fancy", head_length=0.2)
41804245
4181-
Without argument (or with arrowstyle=None), return
4182-
available box styles as a list of strings.
41834246
"""
41844247

41854248
if arrowstyle is None:
@@ -4193,30 +4256,38 @@ def set_arrowstyle(self, arrowstyle=None, **kw):
41934256

41944257
def get_arrowstyle(self):
41954258
"""
4196-
Return the arrowstyle object
4259+
Return the arrowstyle object.
41974260
"""
41984261
return self._arrow_transmuter
41994262

42004263
def set_mutation_scale(self, scale):
42014264
"""
42024265
Set the mutation scale.
42034266
4204-
ACCEPTS: float
4267+
Parameters
4268+
----------
4269+
scale : scalar
42054270
"""
42064271
self._mutation_scale = scale
42074272
self.stale = True
42084273

42094274
def get_mutation_scale(self):
42104275
"""
42114276
Return the mutation scale.
4277+
4278+
Returns
4279+
-------
4280+
scale : scalar
42124281
"""
42134282
return self._mutation_scale
42144283

42154284
def set_mutation_aspect(self, aspect):
42164285
"""
42174286
Set the aspect ratio of the bbox mutation.
42184287
4219-
ACCEPTS: float
4288+
Parameters
4289+
----------
4290+
aspect : scalar
42204291
"""
42214292
self._mutation_aspect = aspect
42224293
self.stale = True
@@ -4229,9 +4300,9 @@ def get_mutation_aspect(self):
42294300

42304301
def get_path(self):
42314302
"""
4232-
return the path of the arrow in the data coordinate. Use
4303+
Return the path of the arrow in the data coordinates. Use
42334304
get_path_in_displaycoord() method to retrieve the arrow path
4234-
in the display coord.
4305+
in display coordinates.
42354306
"""
42364307
_path, fillable = self.get_path_in_displaycoord()
42374308

@@ -4242,7 +4313,7 @@ def get_path(self):
42424313

42434314
def get_path_in_displaycoord(self):
42444315
"""
4245-
Return the mutated path of the arrow in the display coord
4316+
Return the mutated path of the arrow in display coordinates.
42464317
"""
42474318

42484319
dpi_cor = self.get_dpi_cor()
@@ -4260,13 +4331,12 @@ def get_path_in_displaycoord(self):
42604331
_path = self.get_transform().transform_path(self._path_original)
42614332

42624333
_path, fillable = self.get_arrowstyle()(
4263-
_path,
4264-
self.get_mutation_scale() * dpi_cor,
4265-
self.get_linewidth() * dpi_cor,
4266-
self.get_mutation_aspect()
4267-
)
4334+
_path,
4335+
self.get_mutation_scale() * dpi_cor,
4336+
self.get_linewidth() * dpi_cor,
4337+
self.get_mutation_aspect())
42684338

4269-
#if not fillable:
4339+
# if not fillable:
42704340
# self._fill = False
42714341

42724342
return _path, fillable
@@ -4313,7 +4383,7 @@ def draw(self, renderer):
43134383
# FIXME : dpi_cor is for the dpi-dependecy of the
43144384
# linewidth. There could be room for improvement.
43154385
#
4316-
#dpi_cor = renderer.points_to_pixels(1.)
4386+
# dpi_cor = renderer.points_to_pixels(1.)
43174387
self.set_dpi_cor(renderer.points_to_pixels(1.))
43184388
path, fillable = self.get_path_in_displaycoord()
43194389

0 commit comments

Comments
 (0)