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

Skip to content

Commit 76fe3ab

Browse files
authored
Merge pull request #11922 from timhoffm/doc-line2d
Improve docstrings of Line2D
2 parents b02c22d + b9b2f19 commit 76fe3ab

File tree

1 file changed

+82
-55
lines changed

1 file changed

+82
-55
lines changed

lib/matplotlib/lines.py

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def contains(self, mouseevent):
492492
return len(ind) > 0, dict(ind=ind)
493493

494494
def get_pickradius(self):
495-
"""return the pick radius used for containment tests"""
495+
"""Return the pick radius used for containment tests."""
496496
return self.pickradius
497497

498498
def set_pickradius(self, d):
@@ -507,18 +507,27 @@ def set_pickradius(self, d):
507507

508508
def get_fillstyle(self):
509509
"""
510-
return the marker fillstyle
510+
Return the marker fillstyle.
511511
"""
512512
return self._marker.get_fillstyle()
513513

514514
def set_fillstyle(self, fs):
515515
"""
516-
Set the marker fill style; 'full' means fill the whole marker.
517-
'none' means no filling; other options are for half-filled markers.
516+
Set the marker fill style.
518517
519518
Parameters
520519
----------
521520
fs : {'full', 'left', 'right', 'bottom', 'top', 'none'}
521+
Possible values:
522+
523+
- 'full': Fill the whole marker with the *markerfacecolor*.
524+
- 'left', 'right', 'bottom', 'top': Fill the marker half at
525+
the given side with the *markerfacecolor*. The other
526+
half of the marker is filled with *markerfacecoloralt*.
527+
- 'none': No filling.
528+
529+
For examples see
530+
:doc:`/gallery/lines_bars_and_markers/marker_fillstyle_reference`.
522531
"""
523532
self._marker.set_fillstyle(fs)
524533
self.stale = True
@@ -576,7 +585,7 @@ def set_markevery(self, every):
576585
self._markevery = every
577586

578587
def get_markevery(self):
579-
"""return the markevery setting"""
588+
"""Return the markevery setting."""
580589
return self._markevery
581590

582591
def set_picker(self, p):
@@ -619,7 +628,7 @@ def axes(self, ax):
619628

620629
def set_data(self, *args):
621630
"""
622-
Set the x and y data
631+
Set the x and y data.
623632
624633
ACCEPTS: 2D array (rows are x, y) or two 1D arrays
625634
"""
@@ -702,7 +711,7 @@ def _get_transformed_path(self):
702711

703712
def set_transform(self, t):
704713
"""
705-
set the Transformation instance used by this artist
714+
Set the Transformation instance used by this artist.
706715
707716
Parameters
708717
----------
@@ -714,13 +723,13 @@ def set_transform(self, t):
714723
self.stale = True
715724

716725
def _is_sorted(self, x):
717-
"""return True if x is sorted in ascending order"""
726+
"""Return whether x is sorted in ascending order."""
718727
# We don't handle the monotonically decreasing case.
719728
return _path.is_sorted(x)
720729

721730
@allow_rasterization
722731
def draw(self, renderer):
723-
"""draw the Line with `renderer` unless visibility is False"""
732+
"""Draw the Line with *renderer* unless visibility is *False*."""
724733
if not self.get_visible():
725734
return
726735

@@ -851,9 +860,11 @@ def draw(self, renderer):
851860
self.stale = False
852861

853862
def get_antialiased(self):
863+
"""Return whether antialiased rendering is used."""
854864
return self._antialiased
855865

856866
def get_color(self):
867+
"""Return the line color."""
857868
return self._color
858869

859870
def get_drawstyle(self):
@@ -967,7 +978,7 @@ def set_antialiased(self, b):
967978

968979
def set_color(self, color):
969980
"""
970-
Set the color of the line
981+
Set the color of the line.
971982
972983
Parameters
973984
----------
@@ -978,16 +989,28 @@ def set_color(self, color):
978989

979990
def set_drawstyle(self, drawstyle):
980991
"""
981-
Set the drawstyle of the plot
992+
Set the drawstyle of the plot.
982993
983-
'default' connects the points with lines. The steps variants
984-
produce step-plots. 'steps' is equivalent to 'steps-pre' and
985-
is maintained for backward-compatibility.
994+
The drawstyle determines how the points are connected.
986995
987996
Parameters
988997
----------
989998
drawstyle : {'default', 'steps', 'steps-pre', 'steps-mid', \
990-
'steps-post'}
999+
'steps-post'}, default: 'default'
1000+
For 'default', the points are connected with straight lines.
1001+
1002+
The steps variants connect the points with step-like lines,
1003+
i.e. horizontal lines with vertical steps. They differ in the
1004+
location of the step:
1005+
1006+
- 'steps-pre': The step is at the beginning of the line segment,
1007+
i.e. the line will be at the y-value of point to the right.
1008+
- 'steps-mid': The step is halfway between the points.
1009+
- 'steps-post: The step is at the end of the line segment,
1010+
i.e. the line will be at the y-value of the point to the left.
1011+
- 'steps' is equal to 'steps-pre' and is maintained for
1012+
backward-compatibility.
1013+
9911014
"""
9921015
if drawstyle is None:
9931016
drawstyle = 'default'
@@ -1001,7 +1024,7 @@ def set_drawstyle(self, drawstyle):
10011024

10021025
def set_linewidth(self, w):
10031026
"""
1004-
Set the line width in points
1027+
Set the line width in points.
10051028
10061029
Parameters
10071030
----------
@@ -1017,9 +1040,10 @@ def set_linewidth(self, w):
10171040
self._us_dashOffset, self._us_dashSeq, self._linewidth)
10181041

10191042
def _split_drawstyle_linestyle(self, ls):
1020-
'''Split drawstyle from linestyle string
1043+
"""
1044+
Split drawstyle from linestyle string.
10211045
1022-
If `ls` is only a drawstyle default to returning a linestyle
1046+
If *ls* is only a drawstyle default to returning a linestyle
10231047
of '-'.
10241048
10251049
Parameters
@@ -1035,48 +1059,43 @@ def _split_drawstyle_linestyle(self, ls):
10351059
10361060
ls : str
10371061
The linestyle with the drawstyle (if any) stripped.
1038-
'''
1062+
"""
10391063
for ds in self.drawStyleKeys: # long names are first in the list
10401064
if ls.startswith(ds):
10411065
return ds, ls[len(ds):] or '-'
10421066
return None, ls
10431067

10441068
def set_linestyle(self, ls):
10451069
"""
1046-
Set the linestyle of the line (also accepts drawstyles,
1047-
e.g., ``'steps--'``)
1048-
1070+
Set the linestyle of the line.
10491071
1050-
=========================== =================
1051-
linestyle description
1052-
=========================== =================
1053-
``'-'`` or ``'solid'`` solid line
1054-
``'--'`` or ``'dashed'`` dashed line
1055-
``'-.'`` or ``'dashdot'`` dash-dotted line
1056-
``':'`` or ``'dotted'`` dotted line
1057-
``'None'`` draw nothing
1058-
``' '`` draw nothing
1059-
``''`` draw nothing
1060-
=========================== =================
1061-
1062-
'steps' is equivalent to 'steps-pre' and is maintained for
1063-
backward-compatibility.
1072+
Parameters
1073+
----------
1074+
ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
1075+
Possible values:
10641076
1065-
Alternatively a dash tuple of the following form can be provided::
1077+
- A string:
10661078
1067-
(offset, onoffseq),
1079+
=============================== =================
1080+
Linestyle Description
1081+
=============================== =================
1082+
``'-'`` or ``'solid'`` solid line
1083+
``'--'`` or ``'dashed'`` dashed line
1084+
``'-.'`` or ``'dashdot'`` dash-dotted line
1085+
``':'`` or ``'dotted'`` dotted line
1086+
``'None'`` or ``' '`` or ``''`` draw nothing
1087+
=============================== =================
10681088
1069-
where ``onoffseq`` is an even length tuple of on and off ink in points.
1089+
Optionally, the string may be preceded by a drawstyle, e.g.
1090+
``'steps--'``. See :meth:`set_drawstyle` for details.
10701091
1071-
.. seealso::
1092+
- Alternatively a dash tuple of the following form can be
1093+
provided::
10721094
1073-
:meth:`set_drawstyle`
1074-
To set the drawing style (stepping) of the plot.
1095+
(offset, onoffseq)
10751096
1076-
Parameters
1077-
----------
1078-
ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
1079-
The line style.
1097+
where ``onoffseq`` is an even length tuple of on and off ink
1098+
in points. See also :meth:`set_dashes`.
10801099
"""
10811100
if isinstance(ls, str):
10821101
ds, ls = self._split_drawstyle_linestyle(ls)
@@ -1110,7 +1129,7 @@ def set_marker(self, marker):
11101129
11111130
Parameters
11121131
----------
1113-
marker: marker style
1132+
marker : marker style
11141133
See `~matplotlib.markers` for full description of possible
11151134
arguments.
11161135
"""
@@ -1213,13 +1232,19 @@ def set_ydata(self, y):
12131232

12141233
def set_dashes(self, seq):
12151234
"""
1216-
Set the dash sequence, sequence of dashes with on off ink in
1217-
points. If seq is empty or if seq = (None, None), the
1218-
linestyle will be set to solid.
1235+
Set the dash sequence.
1236+
1237+
The dash sequence is a sequence of floats of even length describing
1238+
the length of dashes and spaces in points.
1239+
1240+
For example, (5, 2, 1, 2) describes a sequence of 5 point and 1 point
1241+
dashes separated by 2 point spaces.
12191242
12201243
Parameters
12211244
----------
12221245
seq : sequence of floats (on/off ink in points) or (None, None)
1246+
If *seq* is empty or ``(None, None)``, the linestyle will be set
1247+
to solid.
12231248
"""
12241249
if seq == (None, None) or len(seq) == 0:
12251250
self.set_linestyle('-')
@@ -1258,6 +1283,7 @@ def set_dash_joinstyle(self, s):
12581283
Parameters
12591284
----------
12601285
s : {'miter', 'round', 'bevel'}
1286+
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
12611287
"""
12621288
s = s.lower()
12631289
if s not in self.validJoin:
@@ -1274,6 +1300,7 @@ def set_solid_joinstyle(self, s):
12741300
Parameters
12751301
----------
12761302
s : {'miter', 'round', 'bevel'}
1303+
For examples see :doc:`/gallery/lines_bars_and_markers/joinstyle`.
12771304
"""
12781305
s = s.lower()
12791306
if s not in self.validJoin:
@@ -1286,13 +1313,13 @@ def set_solid_joinstyle(self, s):
12861313

12871314
def get_dash_joinstyle(self):
12881315
"""
1289-
Get the join style for dashed linestyles
1316+
Get the join style for dashed linestyles.
12901317
"""
12911318
return self._dashjoinstyle
12921319

12931320
def get_solid_joinstyle(self):
12941321
"""
1295-
Get the join style for solid linestyles
1322+
Get the join style for solid linestyles.
12961323
"""
12971324
return self._solidjoinstyle
12981325

@@ -1330,18 +1357,18 @@ def set_solid_capstyle(self, s):
13301357

13311358
def get_dash_capstyle(self):
13321359
"""
1333-
Get the cap style for dashed linestyles
1360+
Get the cap style for dashed linestyles.
13341361
"""
13351362
return self._dashcapstyle
13361363

13371364
def get_solid_capstyle(self):
13381365
"""
1339-
Get the cap style for solid linestyles
1366+
Get the cap style for solid linestyles.
13401367
"""
13411368
return self._solidcapstyle
13421369

13431370
def is_dashed(self):
1344-
'return True if line is dashstyle'
1371+
"""Return whether line is dashstyle."""
13451372
return self._linestyle in ('--', '-.', ':')
13461373

13471374

0 commit comments

Comments
 (0)