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

Skip to content

Commit 8ea5142

Browse files
committed
Numpydocify setp.
1 parent 327cfcf commit 8ea5142

File tree

1 file changed

+48
-35
lines changed

1 file changed

+48
-35
lines changed

lib/matplotlib/artist.py

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ def pprint_getters(self):
15581558

15591559
def getp(obj, property=None):
15601560
"""
1561-
Return the value of an object's *property*, or print all of them.
1561+
Return the value of an `.Artist`'s *property*, or print all of them.
15621562
15631563
Parameters
15641564
----------
@@ -1579,6 +1579,10 @@ def getp(obj, property=None):
15791579
e.g.:
15801580
15811581
linewidth or lw = 2
1582+
1583+
See Also
1584+
--------
1585+
setp
15821586
"""
15831587
if property is None:
15841588
insp = ArtistInspector(obj)
@@ -1593,52 +1597,61 @@ def getp(obj, property=None):
15931597

15941598
def setp(obj, *args, file=None, **kwargs):
15951599
"""
1596-
Set a property on an artist object.
1600+
Set one or more properties on an `.Artist`, or list allowed values.
1601+
1602+
Parameters
1603+
----------
1604+
obj : `.Artist` or list of `.Artist`
1605+
The artist(s) whose properties are being set or queried. When setting
1606+
properties, all artists are affected; when querying the allowed values,
1607+
only the first instance in the sequence is queried.
15971608
1598-
matplotlib supports the use of :func:`setp` ("set property") and
1599-
:func:`getp` to set and get object properties, as well as to do
1600-
introspection on the object. For example, to set the linestyle of a
1601-
line to be dashed, you can do::
1609+
For example, two lines can be made thicker and red with a single call:
16021610
1603-
>>> line, = plot([1, 2, 3])
1604-
>>> setp(line, linestyle='--')
1611+
>>> x = arange(0, 1, 0.01)
1612+
>>> lines = plot(x, sin(2*pi*x), x, sin(4*pi*x))
1613+
>>> setp(lines, linewidth=2, color='r')
16051614
1606-
If you want to know the valid types of arguments, you can provide
1607-
the name of the property you want to set without a value::
1615+
file : file-like, default: `sys.stdout`
1616+
Where `setp` writes its output when asked to list allowed values.
16081617
1609-
>>> setp(line, 'linestyle')
1610-
linestyle: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
1618+
>>> with open('output.log') as file:
1619+
... setp(line, file=file)
1620+
1621+
The default, ``None``, means `sys.stdout`.
16111622
1612-
If you want to see all the properties that can be set, and their
1613-
possible values, you can do::
1623+
*args, **kwargs
1624+
The properties to set. The following combinations are supported:
16141625
1615-
>>> setp(line)
1616-
... long output listing omitted
1626+
- Set the linestyle of a line to be dashed:
16171627
1618-
By default `setp` prints to `sys.stdout`, but this can be modified using
1619-
the *file* keyword-only argument::
1628+
>>> line, = plot([1, 2, 3])
1629+
>>> setp(line, linestyle='--')
1630+
1631+
- Set multiple properties at once:
1632+
1633+
>>> setp(line, linewidth=2, color='r')
1634+
1635+
- List allowed values for a line's linestyle:
1636+
1637+
>>> setp(line, 'linestyle')
1638+
linestyle: {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
16201639
1621-
>>> with fopen('output.log') as f:
1622-
>>> setp(line, file=f)
1640+
- List all properties that can be set, and their allowed values:
16231641
1624-
:func:`setp` operates on a single instance or a iterable of
1625-
instances. If you are in query mode introspecting the possible
1626-
values, only the first instance in the sequence is used. When
1627-
actually setting values, all the instances will be set. e.g.,
1628-
suppose you have a list of two lines, the following will make both
1629-
lines thicker and red::
1642+
>>> setp(line)
1643+
agg_filter: a filter function, ...
1644+
[long output listing omitted]
16301645
1631-
>>> x = arange(0, 1, 0.01)
1632-
>>> y1 = sin(2*pi*x)
1633-
>>> y2 = sin(4*pi*x)
1634-
>>> lines = plot(x, y1, x, y2)
1635-
>>> setp(lines, linewidth=2, color='r')
1646+
`setp` also supports MATLAB style string/value pairs. For example, the
1647+
following are equivalent:
16361648
1637-
:func:`setp` works with the MATLAB style string/value pairs or
1638-
with python kwargs. For example, the following are equivalent::
1649+
>>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style
1650+
>>> setp(lines, linewidth=2, color='r') # Python style
16391651
1640-
>>> setp(lines, 'linewidth', 2, 'color', 'r') # MATLAB style
1641-
>>> setp(lines, linewidth=2, color='r') # python style
1652+
See Also
1653+
--------
1654+
getp
16421655
"""
16431656

16441657
if isinstance(obj, Artist):

0 commit comments

Comments
 (0)