File tree Expand file tree Collapse file tree 3 files changed +28
-5
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +28
-5
lines changed
Original file line number Diff line number Diff line change
1
+ `Artist.setp ` (and `pyplot.setp `) accept a `file ` argument
2
+ ----------------------------------------------------------
3
+
4
+ The argument is keyword-only. It allows an output file other than
5
+ `sys.stdout ` to be specified. It works exactly like the `file ` argument
6
+ to `print `.
7
+
Original file line number Diff line number Diff line change @@ -1521,6 +1521,12 @@ def setp(obj, *args, **kwargs):
1521
1521
>>> setp(line)
1522
1522
... long output listing omitted
1523
1523
1524
+ You may specify another output file to `setp` if `sys.stdout` is not
1525
+ acceptable for some reason using the `file` keyword-only argument::
1526
+
1527
+ >>> with fopen('output.log') as f:
1528
+ >>> setp(line, file=f)
1529
+
1524
1530
:func:`setp` operates on a single instance or a iterable of
1525
1531
instances. If you are in query mode introspecting the possible
1526
1532
values, only the first instance in the sequence is used. When
@@ -1548,12 +1554,16 @@ def setp(obj, *args, **kwargs):
1548
1554
1549
1555
insp = ArtistInspector (objs [0 ])
1550
1556
1551
- if len (kwargs ) == 0 and len (args ) == 0 :
1552
- print ('\n ' .join (insp .pprint_setters ()))
1553
- return
1557
+ # file has to be popped before checking if kwargs is empty
1558
+ printArgs = {}
1559
+ if 'file' in kwargs :
1560
+ printArgs ['file' ] = kwargs .pop ('file' )
1554
1561
1555
- if len (kwargs ) == 0 and len (args ) == 1 :
1556
- print (insp .pprint_setters (prop = args [0 ]))
1562
+ if not kwargs and len (args ) < 2 :
1563
+ if args :
1564
+ print (insp .pprint_setters (prop = args [0 ]), ** printArgs )
1565
+ else :
1566
+ print ('\n ' .join (insp .pprint_setters ()), ** printArgs )
1557
1567
return
1558
1568
1559
1569
if len (args ) % 2 :
Original file line number Diff line number Diff line change @@ -211,12 +211,18 @@ def test_properties():
211
211
212
212
@cleanup
213
213
def test_setp ():
214
+ # Check arbitrary iterables
214
215
fig , axes = plt .subplots ()
215
216
lines1 = axes .plot (range (3 ))
216
217
lines2 = axes .plot (range (3 ))
217
218
martist .setp (chain (lines1 , lines2 ), 'lw' , 5 )
218
219
plt .setp (axes .spines .values (), color = 'green' )
219
220
221
+ # Check `file` argument
222
+ sio = io .StringIO ()
223
+ plt .setp (lines1 , 'zorder' , file = sio )
224
+ assert sio .getvalue () == ' zorder: any number \n '
225
+
220
226
221
227
if __name__ == '__main__' :
222
228
import nose
You can’t perform that action at this time.
0 commit comments